Skip to content

Instantly share code, notes, and snippets.

@fredyr
Created July 27, 2014 09:58
Show Gist options
  • Save fredyr/ddd9f1474b38a0ad053b to your computer and use it in GitHub Desktop.
Save fredyr/ddd9f1474b38a0ad053b to your computer and use it in GitHub Desktop.
-- Fixed point registers
data Rx = R0 | R1 | R2 | R3 | R4 | R5 | R6 | R7 deriving (Show, Eq, Ord)
-- Floating point registers
data Fx = F0 | F1 | F2 | F3 | F4 | F5 | F6 | F7 deriving (Show, Eq, Ord)
data Expr :: * -> * where
AddI :: Rx -> Rx -> Expr Integer
SubI :: Rx -> Rx -> Expr Integer
AddF :: Fx -> Fx -> Expr Float
SubF :: Fx -> Fx -> Expr Float
class ALU a b | a -> b where
add :: a -> a -> b
sub :: a -> a -> b
instance ALU Rx (Expr Integer) where
add m n = AddI m n
sub m n = SubI m n
instance ALU Fx (Expr Float) where
add m n = AddF m n
sub m n = SubF m n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment