Permalink
Browse files

Split out the FunC type class in two new type classes: LamFunC and Ap…

…pFunC.

This is useful for languages like SQL which do have function application, but where you can't define your own functions.
Suggested by Martijn van Steenbergen.
  • Loading branch information...
1 parent c686d62 commit 03ce904a3c8487dfe4256c4ff58448f1934d62a7 @tomlokhorst committed Feb 25, 2010
Showing with 16 additions and 4 deletions.
  1. +10 −2 src/Generic/Control/Function.hs
  2. +3 −1 src/Lang/Haskell.hs
  3. +3 −1 src/Lang/JavaScript.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
+{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, UndecidableInstances #-}
module Generic.Control.Function where
@@ -11,10 +11,18 @@ undefined = Prelude.undefined
class NameC j where
named :: Prelude.String -> j a -> j a
-class NameC j => FunC j where
+class NameC j => LamFunC j where
lam :: (j a -> j b) -> j (a -> b)
+
+class NameC j => AppFunC j where
app :: j (a -> b) -> j a -> j b
+class (NameC j, LamFunC j, AppFunC j) => FunC j
+
+instance (NameC j, LamFunC j, AppFunC j) => FunC j
+-- Not a fan of UndecidableInstances (then again, who is), but this sorta works
+-- http://martijn.van.steenbergen.nl/journal/2009/10/11/context-synonyms/
+
class FunC j => RecFunC j where
fix :: (j (a -> b) -> j (a -> b)) -> j (a -> b)
View
@@ -18,8 +18,10 @@ instance NameC Haskell where
type instance H (a -> b) = H a -> H b
-instance FunC Haskell where
+instance LamFunC Haskell where
lam f = Hs (\x -> runHaskell (f (Hs x)))
+
+instance AppFunC Haskell where
app (Hs f) (Hs x) = Hs (f x)
instance RecFunC Haskell where
@@ -17,8 +17,10 @@ type JavaScript a = Val JS a
instance NameC (Val JS) where
named s a = s `Name` a
-instance FunC (Val JS) where
+instance LamFunC (Val JS) where
lam f = Lam f
+
+instance AppFunC (Val JS) where
app f x = App f x
instance RecFunC (Val JS) where

0 comments on commit 03ce904

Please sign in to comment.