lude

Haskell prelude alternative
git clone git://git.rr3.xyz/lude | git clone gits://git.rr3.xyz/lude
Log | Files | Refs | README | LICENSE

Defunctionalization.hs (1513B)


      1 {-# LANGUAGE UndecidableInstances #-}
      2 
      3 module Lude.Haskell.Defunctionalization (
      4 
      5 ) where
      6 
      7 import Lude.Haskell.Core
      8 
      9 -- TODO: All this is tentative. It's mostly for functors which aren't determined
     10 -- by their object map.
     11 
     12 --------------------------------------------------------------------------------
     13 
     14 data TBrand :: Kind -> Brand
     15 
     16 -- | A type expression (of a given kind)
     17 type T k = OpenKind (TBrand k)
     18 
     19 type Splice :: forall {k}. T k -> k
     20 type family Splice _
     21 
     22 data Quote :: forall {k}. k -> T k
     23 type instance Splice (Quote a) = a
     24 
     25 -- | Defunctionalized @(->)@
     26 type (-->) :: Kind -> Kind -> Kind
     27 type k --> l = k -> T l
     28 
     29 infixr 1 -->
     30 
     31 type Apply :: forall {k} {l}. (k --> l) -> k -> l
     32 type Apply f a = Splice (f a)
     33 
     34 type (@@) :: forall {k} {l}. (k --> l) -> k -> l
     35 type f @@ a = Apply f a
     36 infixl 7 @@
     37 
     38 type Defun = Defun1
     39 data Defun1 :: forall k0 k. (k0 -> k) -> (k0 --> k)
     40 type instance Splice (Defun1 f a) = f a
     41 
     42 data Defun2 :: forall k0 k1 k. (k0 -> k1 -> k) -> (k0 --> k1 --> k)
     43 type instance Splice (Defun2 f a) = Defun1 (f a)
     44 
     45 data Defun3 :: forall k0 k1 k2 k. (k0 -> k1 -> k2 -> k) -> (k0 --> k1 --> k2 --> k)
     46 type instance Splice (Defun3 f a) = Defun2 (f a)
     47 
     48 data Defun4 :: forall k0 k1 k2 k3 k. (k0 -> k1 -> k2 -> k3 -> k) -> (k0 --> k1 --> k2 --> k3 --> k)
     49 type instance Splice (Defun4 f a) = Defun3 (f a)
     50 
     51 type Ident :: forall {k}. k --> k
     52 type Ident = Quote
     53 
     54 data Compose :: forall {k} {l} {m}. (l --> m) -> (k --> l) -> (k --> m)
     55 type instance Splice (Compose f g x) = Splice (f (Splice (g x)))