Re: [Haskell-cafe] Non Empty List?

2009-06-05 Thread Conor McBride
Hi folks data NE x = x : Maybe (NE x) ? It's Applicative in at least four different ways. Can anyone find more? Conor On 5 Jun 2009, at 01:34, Edward Kmett wrote: Günther, Miguel had the easiest suggestion to get right: Your goal is to avoid the redundant encoding of a list of one

[Haskell-cafe] Non Empty List?

2009-06-04 Thread GüŸnther Schmidt
Hi, I need to design a container data structure that by design cannot be empty and can hold n elements. Something like a non-empty list. I started with: data Container a = Single a | Many a [a] but the problem above is that the data structure would allow to construct a

Re: [Haskell-cafe] Non Empty List?

2009-06-04 Thread Miguel Mitrofanov
data Container a = Container a [a] ? Or, maybe, you need something like zipper. On 5 Jun 2009, at 01:53, GüŸnther Schmidt wrote: Hi, I need to design a container data structure that by design cannot be empty and can hold n elements. Something like a non-empty list. I started with: data

Re: [Haskell-cafe] Non Empty List?

2009-06-04 Thread Jake McArthur
GüŸnther Schmidt wrote: data Container a = Single a | Many a [a] but the problem above is that the data structure would allow to construct a Many 5 [] :: Container Int. I think you meant to do either data Container a = Single a | Many a (Container a) or data Container a =

Re: [Haskell-cafe] Non Empty List?

2009-06-04 Thread Tom Lokhorst
Are you looking for something like Streams [1]? They're infinite sequences, defined like this: data Stream a = Cons a (Stream a) They can obviously never be empty (unless you see bottom (undefined) as empty). - Tom [1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Stream On Thu,

Re: [Haskell-cafe] Non Empty List?

2009-06-04 Thread Edward Kmett
Günther, Miguel had the easiest suggestion to get right: Your goal is to avoid the redundant encoding of a list of one element, so why do you need to get rid of the Many a [] case when you can get rid of your Single a case! module NE where import Prelude hiding (foldr, foldl, foldl1, head,