Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {-# Language
  2.  DataKinds,
  3.  TypeOperators,
  4.  PolyKinds,
  5.  TypeFamilies,
  6.  UndecidableInstances
  7. #-}
  8.  
  9. data N = Z | S N
  10.  
  11. type family Head (xs :: [a]) :: a where
  12.  Head (x ': xs) = x
  13.  
  14. type family Drop (n :: N) (xs :: [a]) :: [a] where
  15. Drop (S n) (x ': xs) = Drop n xs
  16.  Drop Z xs = xs
  17.  
  18. type family (!!) (xs :: [a]) (n :: N) :: a where
  19.  (!!) xs n = Head (Drop n xs)
  20.  
  21. type StateN (a :: [*]) s = s -> (a !! n,s)
  22. -- obviously wrong, how does it use n?
  23. -- it seems like its trying to emulate a Sum datatype using a type level list,
  24. -- the Nat then is like the constructor for the corresponding position in the Sum type..
  25.  
  26. eg :: StateN '[Bool,Int,Bool] Int
  27. eg = undefined
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement