fork(1) download
  1. {-# LANGUAGE KindSignatures, GADTs, TypeFamilies, TypeOperators, MultiParamTypeClasses, DataKinds #-}
  2.  
  3. import Control.Applicative
  4. import Data.Traversable (Traversable)
  5.  
  6. class (Applicative f, Traversable f) => Dim f
  7.  
  8. class Shapely (fs :: [* -> *])
  9. instance Shapely '[]
  10. instance (Dim f, Shapely fs) => Shapely (f ': fs)
  11.  
  12. -------------------------------------
  13. -- Hypercuboid datatype
  14. -------------------------------------
  15. data Hyper :: [* -> *] -> * -> * where
  16. Scalar :: a -> Hyper '[] a
  17. Prism :: (Dim f, Shapely fs) =>
  18. Hyper fs (f a) -> Hyper (f ': fs) a
  19.  
  20. instance Functor (Hyper fs) where
  21. fmap f (Scalar a) = Scalar $ f a
  22. fmap f (Prism p) = Prism $ fmap (fmap f) p
  23.  
  24. instance Applicative (Hyper fs) where
  25. pure a = undefined
  26. {- `pure a = Scalar a` gives:
  27.   Couldn't match type ‘fs’ with ‘'[]’
  28.   ‘fs’ is a rigid type variable bound by
  29.   the instance declaration
  30.   Expected type: Hyper fs a
  31.   Actual type: Hyper '[] a
  32. -}
  33.  
  34. main = print 42
Success #stdin #stdout 0s 4700KB
stdin
Standard input is empty
stdout
42