Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
95
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.  GADTs,
  8.  RankNTypes
  9. #-}
  10.  
  11. data Nat = Z | S Nat
  12.            deriving (Show, Eq, Ord)
  13.  
  14. type family Head (xs :: [a]) :: a where
  15.  Head (x ': xs) = x
  16.  
  17. type family Drop (n :: Nat) (xs :: [a]) :: [a] where
  18. Drop (S n) (x ': xs) = Drop n xs
  19.  Drop Z xs = xs
  20.  
  21. type family (!!) (xs :: [a]) (n :: Nat) :: a where
  22.  (!!) xs n = Head (Drop n xs)
  23.  
  24. data Proxy n = Proxy
  25. type SumType (xs :: [*]) = forall x (n::Nat). xs !! n ~ x => (Proxy n,x)
  26.  
  27. type Eg = [Bool,Int,Bool]
  28.  
  29. eg :: SumType Eg
  30. eg = (Proxy :: Proxy Z,False)
  31.  
  32. {-
  33.  
  34.     * Could not deduce: n ~ 'Z
  35.       from the context: (Eg !! n) ~ x
  36.         bound by the type signature for:
  37.                    eg :: SumType Eg
  38.       `n' is a rigid type variable bound by
  39.         the type signature for:
  40.           eg :: SumType Eg
  41.       Expected type: Proxy n
  42.         Actual type: Proxy 'Z
  43.     * In the expression: Proxy :: Proxy Z
  44.       In the expression: (Proxy :: Proxy Z, False)
  45.       In an equation for `eg': eg = (Proxy :: Proxy Z, False)
  46.     * Relevant bindings include
  47.         eg :: (Proxy n, x)
  48.    |
  49.    | eg = (Proxy :: Proxy Z,False)
  50.    |       ^^^^^^^^^^^^^^^^
  51.  
  52.     * Could not deduce: x ~ Bool
  53.       from the context: (Eg !! n) ~ x
  54.         bound by the type signature for:
  55.                    eg :: SumType Eg
  56.       `x' is a rigid type variable bound by
  57.         the type signature for:
  58.           eg :: SumType Eg
  59.     * In the expression: False
  60.       In the expression: (Proxy :: Proxy Z, False)
  61.       In an equation for `eg': eg = (Proxy :: Proxy Z, False)
  62.     * Relevant bindings include
  63.         eg :: (Proxy n, x)
  64.    |
  65.    | eg = (Proxy :: Proxy Z,False)
  66.    |                        ^^^^^
  67. -}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement