Re:CIS 194: Introduction to Haskell (Spring 2013)
by quchen on Monday July 29, 2013 @10:39AM
(#6121345)
He used pseudo-notation for something that is possible in GHC. (1+) on type level corresponds to the successor function, and a compiling version of Peaker's code would be this:
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
data Nat = Z | S Nat
data Vector l a where
Nil :: Vector Z a
Cons :: a -> Vector l a -> Vector (S l) a
Re:CIS 194: Introduction to Haskell (Spring 2013)
by jdn on Monday July 29, 2013 @11:29AM
(#6121682)
Thanks for this! Had looked at examples of this but it's nice to have the link to Peaker's code
Re:CIS 194: Introduction to Haskell (Spring 2013)
by klibertp on Monday July 29, 2013 @08:53AM
(#6120696)
Not in Haskell, but there are languages where it's possible. It's called dependent typing and I don't really understand how it works, but I suppose gp was referring to this.
Re:CIS 194: Introduction to Haskell (Spring 2013)
by sold on Monday July 29, 2013 @10:40AM
(#6121351)
It is possible in GHC, see parent comment.
Re:CIS 194: Introduction to Haskell (Spring 2013)
by jdn on Monday July 29, 2013 @09:01AM
(#6120750)
Oh of course, and that also explains the use of GADTs since they are one route to dependent types in Haskell. I'm not sure what he's done there is fully legit, but maybe not as loony as at first thought.
> Cons :: a -> Vector n a --> Vector (1 + n) a
This makes no sense, you can't specify constants in a type signature, and you certainly can't add constants to a type variable in one.
I may be the one not in the know here, if so please show me this magic.