Created
May 4, 2010 12:36
-
-
Save sjoerdvisscher/389359 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE NoMonomorphismRestriction, TypeSynonymInstances, FlexibleInstances, MultiParamTypeClasses #-} | |
class ExpSYM repr where | |
lit :: Int -> repr | |
neg :: repr -> repr | |
add :: repr -> repr -> repr | |
class Ann repr e where | |
a :: e -> repr -> repr | |
instance ExpSYM Int where | |
lit n = n | |
neg e = - e | |
add e1 e2 = e1 + e2 | |
instance Ann Int e where | |
a e = id | |
instance ExpSYM String where | |
lit n = show n | |
neg e = "(-" ++ e ++ ")" | |
add e1 e2 = "(" ++ e1 ++ " + " ++ e2 ++ ")" | |
instance Show a => Ann String a where | |
a e s = "@" ++ show e ++ " " ++ s | |
data P = P Int Int | |
instance Show P where show (P x y) = "(" ++ show x ++ "," ++ show y ++ ")" | |
tf1 = add (lit 8) (neg (add (lit 1) (lit 2))) | |
tf2 = a (P 1 1) $ add (a (P 2 1) $ lit 8) (a (P 3 1) $ neg (a (P 4 1) $ add (a (P 5 1) $ lit 1) (a (P 6 1) $ lit 2))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment