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
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
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
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 =
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,
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,