diff options
author | Tom Smeding <tom@tomsmeding.com> | 2021-06-24 23:14:54 +0200 |
---|---|---|
committer | Tom Smeding <tom@tomsmeding.com> | 2021-06-24 23:14:54 +0200 |
commit | 0fefe4822c65bde81ec4c0da1b5b32a9b411ca79 (patch) | |
tree | 0efeffb8b1b6d6126bc806209a2f5a64fb32c96f /Examples.hs |
Initial
Diffstat (limited to 'Examples.hs')
-rw-r--r-- | Examples.hs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Examples.hs b/Examples.hs new file mode 100644 index 0000000..9d9cda7 --- /dev/null +++ b/Examples.hs @@ -0,0 +1,28 @@ +module Examples where + +import AST +import qualified Language as L + + +sumSq :: Exp env (Array (Int, ()) Double -> Double) +sumSq = Lam (TArray (STC STZ) TDouble) + (L.sum (App mapSq (Var (TArray (STC STZ) TDouble) Zero))) + +mapSq :: Exp env (Array (Int, ()) Double -> Array (Int, ()) Double) +mapSq = + Lam (TArray (STC STZ) TDouble) + (L.map (Lam TDouble + (App (Const CMulF) + (Pair (Var TDouble Zero) (Var TDouble Zero)))) + (Var (TArray (STC STZ) TDouble) Zero)) + +mapSqIota :: Exp env (Array (Int, ()) Double) +mapSqIota = + L.map (Lam TDouble + (App (Const CMulF) + (Pair (Var TDouble Zero) (Var TDouble Zero)))) + (Build (STC STZ) + (Pair (Lit (LInt 5)) (Lit LNil)) + (Lam (TPair TInt TNil) + (App (Const CtoF) + (Fst (Var (TPair TInt TNil) Zero))))) |