Reputation: 367
Can I have a function in a data constructor? Like:
data Something = (a->b) Something1 Something2
Upvotes: 4
Views: 183
Reputation: 92976
Yeah, of course you can. The only important thing is that you (always) need a name for your data constructor:
data <name> <para0> <param1> ... = <constructor> <arg0> <arg1> <arg2> ...
So for our example, it becomes
data Something a b = Constructor (a -> b) Something1 Something2
Upvotes: 12
Reputation: 11208
There are some rules to be followed in naming of a Constructor.
But ofcourse you can have functions in a data definition like
data Something a b = Something (a->b) a b
Upvotes: 5