Re: [Haskell-cafe] Type level functions (type of decreasing list)

2006-10-18 Thread Stefan Holdermans
Greg, What about the following (tested with GHC 6.6)? {-# OPTIONS -fglasgow-exts #-} data Zero = Zero data Succ n = Succ n zero = Zero one = Succ zero two = Succ one three = Succ two -- etc data Seq :: * - * where Nil :: Seq Zero Cons :: Succ n - Seq n - Seq

[Haskell-cafe] Type level functions (type of decreasing list)

2006-10-17 Thread Greg Buchholz
I'm wondering about creating a data structure that has the type of decreasing numbers. If I want an increasing list, it is easy... {-# OPTIONS -fglasgow-exts #-} data Succ a = S a deriving Show data Zero = Z deriving Show data Seq' a = Cons' a (Seq' (Succ a)) | Nil' deriving

Re: [Haskell-cafe] Type level functions (type of decreasing list)

2006-10-17 Thread Spencer Janssen
Here's an attempt with GADTs: \begin{code} {-# OPTIONS_GHC -fglasgow-exts #-} data Succ a data Zero data Seq a b where Cons :: a - Seq a b - Seq a (Succ b) Nil :: Seq a Zero \end{code} Seems to work for me. Spencer Janssen On Oct 17, 2006, at 6:37 PM, Greg Buchholz wrote: I'm

Re: [Haskell-cafe] Type level functions (type of decreasing list)

2006-10-17 Thread Greg Buchholz
Spencer Janssen wrote: ] Here's an attempt with GADTs: ] ] \begin{code} ] {-# OPTIONS_GHC -fglasgow-exts #-} ] data Succ a ] data Zero ] data Seq a b where ] Cons :: a - Seq a b - Seq a (Succ b) ] Nil :: Seq a Zero ] \end{code} ] ] Seems to work for me. Hmm. Maybe I'm missing