{-# LANGUAGE FlexibleInstances, ExistentialQuantification, OverlappingInstances, NoMonomorphismRestriction #-} import Data import Code import Term import Value import Control t3 :: (Data m r) => m (r Tint) t3 = do l1 <- lit 1 l2 <- lit 2 add l1 l2 t3v = value \$ t3 -- t3x = genExpr \$ t3 -- , asm \$ liftM (\x -> [x]) (t3 :: MCode Tfloat)) --instance Monad m => CodeApp m () where -- termApp _ () = ([], return []) test1 :: (Code Tfloat) -> (Maybe (Code Tfloat)) test1 x = Just x test2 :: (Code Tfloat) -> (Maybe (Code Tfloat, Code Tfloat)) test2 x = (Just (x,x)) -- Generic type is: -- ExprM r m => r Tfloat -> r Tfloat -> m (r Tfloat, r Tfloat) -- To make it work for CodeApp the type hast to be restricted: test3 _ a b = do s <- add a b p <- mul a b return (s, p) test3' = test3 :: Code Tint -> Code Tfloat -> Code Tfloat -> MCode (Code Tfloat, Code Tfloat) test4 (a,b) = do s <- add a b p <- mul a b return (s, p) test4' = test4 :: (Code Tfloat, Code Tfloat) -> MCode (Code Tfloat, Code Tfloat) test5 a b = do s <- add a b p <- mul a b return (s, p) test5' = test5 :: Code Tfloat -> Code Tfloat -> MCode (Code Tfloat, Code Tfloat) test6 (a, b) = do s <- add a b p <- mul a b return (s, p) test6' = test6 :: (Code Tfloat, Code Tfloat) -> MCode (Code Tfloat, Code Tfloat) -- Expression and function compilation. e1 = term \$ t3 -- f5 = term \$ _lambda (\x -> test5' x x) -- f6 = term \$ _lambda test6' {- -- Generic: this needs a better way to single out the type of function -- that can be passed in. e2 = compile \$ add l l f2 = compile \$ test' -} main = putStrLn \$ show \$ e1