{-# LANGUAGE OverloadedStrings #-} module Examples where import qualified Data.Map as M import Wave.Ast import Wave.Common lit :: File () lit :: File () lit = Expr () -> File () exprToFile (Expr () -> File ()) -> Expr () -> File () forall a b. (a -> b) -> a -> b $ Lit -> Expr () forall a. Lit -> Expr a ELit (Lit -> Expr ()) -> Lit -> Expr () forall a b. (a -> b) -> a -> b $ Int -> Lit LInt Int 7 variant :: File () variant :: File () variant = Expr () -> File () exprToFile (Expr () -> File ()) -> Expr () -> File () forall a b. (a -> b) -> a -> b $ Variant (Expr ()) -> Expr () forall a. Variant (Expr a) -> Expr a EVariant (Variant (Expr ()) -> Expr ()) -> Variant (Expr ()) -> Expr () forall a b. (a -> b) -> a -> b $ Constr -> Expr () -> Variant (Expr ()) forall a. Constr -> a -> Variant a Variant Constr "Foo" (Record (Expr ()) -> Expr () forall a. Record (Expr a) -> Expr a ERecord (Record (Expr ()) -> Expr ()) -> Record (Expr ()) -> Expr () forall a b. (a -> b) -> a -> b $ [(Constr, Expr ())] -> Record (Expr ()) forall k a. Ord k => [(k, a)] -> Map k a M.fromList [(Constr "x", Lit -> Expr () forall a. Lit -> Expr a ELit (Lit -> Expr ()) -> Lit -> Expr () forall a b. (a -> b) -> a -> b $ Constr -> Lit LString Constr "wave")]) patmatch1 :: File () patmatch1 :: File () patmatch1 = Expr () -> File () exprToFile (Expr () -> File ()) -> Expr () -> File () forall a b. (a -> b) -> a -> b $ Expr () -> [(Pattern, Expr ())] -> Expr () forall a. Expr a -> [(Pattern, Expr a)] -> Expr a ECase (Lit -> Expr () forall a. Lit -> Expr a ELit (Lit -> Expr ()) -> Lit -> Expr () forall a b. (a -> b) -> a -> b $ Int -> Lit LInt Int 0) [ (Pattern PWildcard, Lit -> Expr () forall a. Lit -> Expr a ELit (Lit -> Expr ()) -> Lit -> Expr () forall a b. (a -> b) -> a -> b $ Int -> Lit LInt Int 1) ] patmatch2 :: File () patmatch2 :: File () patmatch2 = Expr () -> File () exprToFile (Expr () -> File ()) -> Expr () -> File () forall a b. (a -> b) -> a -> b $ Expr () -> [(Pattern, Expr ())] -> Expr () forall a. Expr a -> [(Pattern, Expr a)] -> Expr a ECase (Lit -> Expr () forall a. Lit -> Expr a ELit (Lit -> Expr ()) -> Lit -> Expr () forall a b. (a -> b) -> a -> b $ Int -> Lit LInt Int 0) [ (Lit -> Pattern PLit (Int -> Lit LInt Int 1), Lit -> Expr () forall a. Lit -> Expr a ELit (Lit -> Expr ()) -> Lit -> Expr () forall a b. (a -> b) -> a -> b $ Int -> Lit LInt Int 1), (Lit -> Pattern PLit (Int -> Lit LInt Int 0), Lit -> Expr () forall a. Lit -> Expr a ELit (Lit -> Expr ()) -> Lit -> Expr () forall a b. (a -> b) -> a -> b $ Int -> Lit LInt Int 0) ] patmatch3 :: File () patmatch3 :: File () patmatch3 = Expr () -> File () exprToFile (Expr () -> File ()) -> Expr () -> File () forall a b. (a -> b) -> a -> b $ Expr () -> [(Pattern, Expr ())] -> Expr () forall a. Expr a -> [(Pattern, Expr a)] -> Expr a ECase (Lit -> Expr () forall a. Lit -> Expr a ELit (Lit -> Expr ()) -> Lit -> Expr () forall a b. (a -> b) -> a -> b $ Int -> Lit LInt Int 17) [ (Lit -> Pattern PLit (Int -> Lit LInt Int 1), Lit -> Expr () forall a. Lit -> Expr a ELit (Lit -> Expr ()) -> Lit -> Expr () forall a b. (a -> b) -> a -> b $ Int -> Lit LInt Int 1), (Lit -> Pattern PLit (Int -> Lit LInt Int 0), Lit -> Expr () forall a. Lit -> Expr a ELit (Lit -> Expr ()) -> Lit -> Expr () forall a b. (a -> b) -> a -> b $ Int -> Lit LInt Int 0), (Constr -> Pattern PVar Constr "v", Constr -> Expr () forall a. Constr -> Expr a EVar Constr "v") ] patmatch4 :: File () patmatch4 :: File () patmatch4 = Expr () -> File () exprToFile (Expr () -> File ()) -> Expr () -> File () forall a b. (a -> b) -> a -> b $ Expr () -> [(Pattern, Expr ())] -> Expr () forall a. Expr a -> [(Pattern, Expr a)] -> Expr a ECase ( Variant (Expr ()) -> Expr () forall a. Variant (Expr a) -> Expr a EVariant (Variant (Expr ()) -> Expr ()) -> Variant (Expr ()) -> Expr () forall a b. (a -> b) -> a -> b $ Constr -> Expr () -> Variant (Expr ()) forall a. Constr -> a -> Variant a Variant Constr "Nil" (Expr () -> Variant (Expr ())) -> Expr () -> Variant (Expr ()) forall a b. (a -> b) -> a -> b $ Record (Expr ()) -> Expr () forall a. Record (Expr a) -> Expr a ERecord (Record (Expr ()) -> Expr ()) -> Record (Expr ()) -> Expr () forall a b. (a -> b) -> a -> b $ [(Constr, Expr ())] -> Record (Expr ()) forall k a. Ord k => [(k, a)] -> Map k a M.fromList [ (Constr "head", Lit -> Expr () forall a. Lit -> Expr a ELit (Lit -> Expr ()) -> Lit -> Expr () forall a b. (a -> b) -> a -> b $ Int -> Lit LInt Int 0), (Constr "tail", Record (Expr ()) -> Expr () forall a. Record (Expr a) -> Expr a ERecord Record (Expr ()) forall a. Monoid a => a mempty) ] ) [ (Variant Pattern -> Pattern PVariant (Variant Pattern -> Pattern) -> Variant Pattern -> Pattern forall a b. (a -> b) -> a -> b $ Constr -> Pattern -> Variant Pattern forall a. Constr -> a -> Variant a Variant Constr "Nil" (Constr -> Pattern PVar Constr "obj"), Expr () -> Constr -> Expr () forall a. Expr a -> Constr -> Expr a ERecordAccess (Constr -> Expr () forall a. Constr -> Expr a EVar Constr "obj") Constr "head") ] patmatch5 :: File () patmatch5 :: File () patmatch5 = Expr () -> File () exprToFile (Expr () -> File ()) -> Expr () -> File () forall a b. (a -> b) -> a -> b $ Expr () -> [(Pattern, Expr ())] -> Expr () forall a. Expr a -> [(Pattern, Expr a)] -> Expr a ECase ( Variant (Expr ()) -> Expr () forall a. Variant (Expr a) -> Expr a EVariant (Variant (Expr ()) -> Expr ()) -> Variant (Expr ()) -> Expr () forall a b. (a -> b) -> a -> b $ Constr -> Expr () -> Variant (Expr ()) forall a. Constr -> a -> Variant a Variant Constr "Nil" (Expr () -> Variant (Expr ())) -> Expr () -> Variant (Expr ()) forall a b. (a -> b) -> a -> b $ Record (Expr ()) -> Expr () forall a. Record (Expr a) -> Expr a ERecord (Record (Expr ()) -> Expr ()) -> Record (Expr ()) -> Expr () forall a b. (a -> b) -> a -> b $ [(Constr, Expr ())] -> Record (Expr ()) forall k a. Ord k => [(k, a)] -> Map k a M.fromList [ (Constr "head", Lit -> Expr () forall a. Lit -> Expr a ELit (Lit -> Expr ()) -> Lit -> Expr () forall a b. (a -> b) -> a -> b $ Int -> Lit LInt Int 0), (Constr "tail", Record (Expr ()) -> Expr () forall a. Record (Expr a) -> Expr a ERecord Record (Expr ()) forall a. Monoid a => a mempty) ] ) [ ( Variant Pattern -> Pattern PVariant (Variant Pattern -> Pattern) -> Variant Pattern -> Pattern forall a b. (a -> b) -> a -> b $ Constr -> Pattern -> Variant Pattern forall a. Constr -> a -> Variant a Variant Constr "Nil" ( Record Pattern -> Pattern PRecord (Record Pattern -> Pattern) -> Record Pattern -> Pattern forall a b. (a -> b) -> a -> b $ [(Constr, Pattern)] -> Record Pattern forall k a. Ord k => [(k, a)] -> Map k a M.fromList [ (Constr "head", Constr -> Pattern PVar Constr "head"), (Constr "tail", Record Pattern -> Pattern PRecord Record Pattern forall a. Monoid a => a mempty) ] ), Constr -> Expr () forall a. Constr -> Expr a EVar Constr "head" ) ] exprToFile :: Expr () -> File () exprToFile :: Expr () -> File () exprToFile Expr () e = [Definition ()] -> File () forall a. [Definition a] -> File a File [ TermDef () -> Definition () forall a. TermDef a -> Definition a TermDef (TermDef () -> Definition ()) -> TermDef () -> Definition () forall a b. (a -> b) -> a -> b $ Constr -> [Constr] -> Sub () -> TermDef () forall a. Constr -> [Constr] -> Sub a -> TermDef a Function Constr "main" [] [Expr () -> Statement () forall a. Expr a -> Statement a SExpr (Expr () -> Statement ()) -> Expr () -> Statement () forall a b. (a -> b) -> a -> b $ Constr -> [Expr ()] -> Expr () forall a. Constr -> [Expr a] -> Expr a EFfi Constr "console.log" [Expr () e]] ]