On Fri, Jun 5, 2009 at 2:58 PM, MH <[email protected]> wrote: > I actually meant > > data Container a = Many a(Container a) > > but here is what I don't understand (fyi, I am a beginner) how can you > construct this container? I can do
I think I saw the above definition described as a coalgebra or codata: http://blog.sigfpe.com/2007/07/data-and-codata.html Basically, that list has to always be infinite. > > > let a = Many "somestring" - and I will get back a function but I can not do > let a = Many 'a' "somestring" - because the second param is not > (Container a) type. > let a = Many 'a' (Container ['a','a']) - doesn't work either because > Container is a type not a constructor (right or I am missing > something?). > > So I have two questions: > 1. When I do > let b = Many "somestring" , I get > :t b > b :: Container[Char] -> Container[Char] > what is it and why I am allowed to pass just one parameter to Many > (and how can I use it)? > > 2. How can you construct that container? > data Container a = Many a(Container a) > let a = ???? > Check that link above for answers to some of your questions. I think that basically you want a different type: data NonEmptyList a = JustOne a | MoreThanOne a (NonEmptyList a) This is just the normal list definition with a small change, if you think of the normal list as being defined in this (pseudo) code: data [a] = [] | a : [a] I've just made it so that the "empty" list has at least one. I hope that helps, Jason
_______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
