Herokiller
Herokiller

Reputation: 2991

How can I match this pattern in haskell

I've got data

LNode(TypedL(2.72489e12,"http://www.w3.org/2001/XMLSchema#double"))

I want an anonymous function to match from this to 2.72489e12

myfunc (LNode(TypedL(c, d))) = c

gives

Constructor `TypedL' should have 2 arguments, but has been given 1.

Is my syntax with this function wrong?

Upvotes: 0

Views: 62

Answers (1)

AJF
AJF

Reputation: 11923

The problem is the way you're calling your function. In Haskell, functions and constructors are called like this:

function arg1 arg2 arg3

So, when it says it wants two arguments, it means this:

myfunc (LNode (TypedL c d)) = c
--                    ~~~ 

Tuples ((a, b, c)) are separate datatypes. They can be used as function arguments if defined, but that's generally seen as unidiomatic Haskell.

Upvotes: 4

Related Questions