fork download
  1. {-# LANGUAGE GADTs, DataKinds, TypeFamilies #-}
  2.  
  3. import Data.List
  4.  
  5. data Peano = Zero | Successor Peano
  6.  
  7. data Vector peanoNum someType where
  8. Nil :: Vector Zero someType
  9. (:+) :: someType -> Vector num someType -> Vector (Successor num) someType
  10.  
  11. infixr 5 :+
  12.  
  13. type family Iterate peanoNum constructor someType where
  14. Iterate Zero cons typ = typ
  15. Iterate (Successor pn) cons typ =
  16. cons (Iterate pn cons typ)
  17.  
  18. showIter :: Vector n a -> Iterate n [] Double -> String
  19. showIter Nil d = show d
  20. showIter (x :+ xs) ds = "[" ++ intercalate ", " (map (showIter xs) ds) ++ "]"
  21.  
  22. main = print $ showIter (undefined :+ undefined :+ Nil) [[1, 2], [4, 5, 6], [7]]
Success #stdin #stdout 0s 4740KB
stdin
Standard input is empty
stdout
"[[1.0, 2.0], [4.0, 5.0, 6.0], [7.0]]"