--- /dev/null
+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
+{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE MultiParamTypeClasses #-}
+module Interpreter where
+
+import Language
+import Control.Monad
+
+newtype Interpreter a = I {runInterpreter :: Maybe a}
+ deriving (Functor, Applicative, Monad)
+
+instance Expression Interpreter where
+ lit = pure
+ (+.) = liftM2 (+)
+ (-.) = liftM2 (-)
+ (/.) = liftM2 (/)
+ (*.) = liftM2 (*)
+ (^.) = liftM2 (^)
+ neg = fmap negate
+ (&.) = liftM2 (&&)
+ (|.) = liftM2 (||)
+ not = fmap Prelude.not
+ (==.) = liftM2 (==)
+ (/=.) = liftM2 (/=)
+ (<.) = liftM2 (<)
+ (>.) = liftM2 (>)
+ (<=.) = liftM2 (<=)
+ (>=.) = liftM2 (>=)
+ if' p t e = p >>= \b->if b then t else e
+
+instance Function a Interpreter where
+ fun def = Main $
+ let g :- m = def g
+ in unmain m