Apparently, with some GHC extensions it is possible to define a type of list that has length encoded in the type, like this:
{-# LANGUAGE GADTs, EmptyDataDecls #-}
data Z
data S a
data List l a where
Nil :: List Z a
Cons :: a -> List l a -> List (S l) a
While I see why this can be useful, I have trouble actually using it.
How can one create such a list? (Apart from hardcoding it into the program.)
Say one would want to create a program that reads two such lists from terminal and computes their dot product. While it is easy to implement the actual multiplicative function, how can the program read the data?
Could you point me to some existing code that uses these techniques?
fromList
gives aUList
, but the function examples you give require aList
. How would you get theList
out of aUList
so that you could apply, say,mapList
? – Alcohol