[Haskell-cafe] fromInteger for Lists

Paul Keir pkeir at dcs.gla.ac.uk
Fri May 1 18:01:30 EDT 2009


There's nothing better than making a data type an instance of Num. In particular, fromInteger is a joy. But how about lists?

For example, if I have

data Foo a = F [a]

I can create a fromInteger such as
fromInteger i = F [fromInteger i]

and then a 19::(Foo Int), could become F [19].

Is it possible to do something similar for lists? So could
[1,2,3]::(Foo Int) become something slightly different, say,

F [1,2,3]

Paul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090501/52441ddb/attachment.htm


More information about the Haskell-Cafe mailing list