Permalink
Browse files

Lang.Haskell now type checks! Using a type family

  • Loading branch information...
1 parent 6bb03db commit a6dd6903134bec8642d704e368944509a045977f @tomlokhorst committed Feb 6, 2010
Showing with 17 additions and 11 deletions.
  1. +17 −11 src/Lang/Haskell.hs
View
@@ -1,4 +1,4 @@
-{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, UndecidableInstances #-}
+{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, TypeFamilies, UndecidableInstances #-}
module Lang.Haskell where
@@ -7,20 +7,26 @@ import qualified Prelude as P
import Generic.Prelude
--- Short, concise name for Identiy wrapper
-newtype Id a = Id { unId :: a }
- deriving P.Show
+type family H a :: *
-runHaskell :: Id a -> a
-runHaskell = unId
+newtype Haskell a = Hs { runHaskell :: H a }
-- * Haskell instances for AwesomePrelude 'data types'.
-instance NameC Id where
- named s a = a -- drop name annotation, for now
+instance NameC Haskell where
+ named _ a = a -- drop name annotation, for now
-instance FunC Id where
- lam f = Id (\x -> unId (f (Id x)))
+type instance H (a -> b) = H a -> H b
+
+instance FunC Haskell where
+ lam f = Hs (\x -> runHaskell (f (Hs x)))
fix f = f (fix f)
- app (Id f) (Id x) = Id (f x)
+ app (Hs f) (Hs x) = Hs (f x)
+
+type instance H Bool = P.Bool
+
+instance BoolC Haskell where
+ false = Hs P.False
+ true = Hs P.True
+ bool x y (Hs b) = if b then y else x

0 comments on commit a6dd690

Please sign in to comment.