diff options
author | Tom Smeding <t.j.smeding@uu.nl> | 2023-09-20 15:53:59 +0200 |
---|---|---|
committer | Tom Smeding <t.j.smeding@uu.nl> | 2023-09-20 15:53:59 +0200 |
commit | 897fefce372f00d3e904e83eb92c83e3e653b5be (patch) | |
tree | b4b36b280ccdd26656723eb5d8b15b8042a97744 /src/Example.hs | |
parent | 183e8b4a07231aae904b8234ddeb1c646c031173 (diff) |
Examples with conditionals
Diffstat (limited to 'src/Example.hs')
-rw-r--r-- | src/Example.hs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/Example.hs b/src/Example.hs index c8f12ba..f2e5966 100644 --- a/src/Example.hs +++ b/src/Example.hs @@ -58,3 +58,39 @@ ex2 = (bin (OAdd STF32) (EVar ext (STScal STF32) IZ) (EVar ext (STScal STF32) (IS (IS IZ)))) + +-- x y |- if x < y then 2 * x else 3 + x +ex3 :: Ex [TScal TF32, TScal TF32] (TScal TF32) +ex3 = + ECase ext (EOp ext OIf (bin (OLt STF32) (EVar ext (STScal STF32) (IS IZ)) + (EVar ext (STScal STF32) IZ))) + (bin (OMul STF32) (EConst ext STF32 2.0) + (EVar ext (STScal STF32) (IS (IS IZ)))) + (bin (OAdd STF32) (EConst ext STF32 3.0) + (EVar ext (STScal STF32) (IS (IS IZ)))) + +-- x y |- if x < y then 2 * x + y * y else 3 + x +ex4 :: Ex [TScal TF32, TScal TF32] (TScal TF32) +ex4 = + ECase ext (EOp ext OIf (bin (OLt STF32) (EVar ext (STScal STF32) (IS IZ)) + (EVar ext (STScal STF32) IZ))) + (bin (OAdd STF32) + (bin (OMul STF32) (EConst ext STF32 2.0) + (EVar ext (STScal STF32) (IS (IS IZ)))) + (bin (OMul STF32) (EVar ext (STScal STF32) (IS IZ)) + (EVar ext (STScal STF32) (IS IZ)))) + (bin (OAdd STF32) (EConst ext STF32 3.0) + (EVar ext (STScal STF32) (IS (IS IZ)))) + +senv5 :: SList STy [TScal TF32, TEither (TScal TF32) (TScal TF32)] +senv5 = STScal STF32 `SCons` STEither (STScal STF32) (STScal STF32) `SCons` SNil + +-- x:R+R y:R |- case x of {inl a -> a * y ; inr b -> b * (y + 1)} +ex5 :: Ex [TScal TF32, TEither (TScal TF32) (TScal TF32)] (TScal TF32) +ex5 = + ECase ext (EVar ext (STEither (STScal STF32) (STScal STF32)) (IS IZ)) + (bin (OMul STF32) (EVar ext (STScal STF32) IZ) + (EVar ext (STScal STF32) (IS IZ))) + (bin (OMul STF32) (EVar ext (STScal STF32) IZ) + (bin (OAdd STF32) (EVar ext (STScal STF32) (IS IZ)) + (EConst ext STF32 1.0))) |