Last active
February 5, 2025 03:00
-
-
Save roboguy13/e386301a24970ec84a9165228dbe4ea8 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
module NumericDSL | |
where | |
---- Example GHCi session: | |
-- ghci> example (10 :: Int) | |
-- 130 | |
-- ghci> example (10 :: Expr) | |
-- Mul (Add (Lit 10) (Lit 3)) (Lit 10) | |
example :: Num a => a -> a | |
example x = (x + 3) * x | |
data Expr | |
= Lit Int | |
| Add Expr Expr | |
| Mul Expr Expr | |
deriving (Show) | |
instance Num Expr where | |
fromInteger x = Lit (fromInteger x) | |
x + y = Add x y | |
x * y = Mul x y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment