Advertisement
Guest User

Untitled

a guest
Aug 6th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {-# LANGUAGE GADTs #-}
  2.  
  3. module Lib where
  4.  
  5. import Data.Map.Strict
  6.  
  7. data Value
  8.     = ValueBool Bool
  9.     | ValueText String
  10.     | ValueObject (Map String Value)
  11.  
  12. data Expr t where
  13.     ExprBool :: Bool -> Expr Bool
  14.     ExprBoolOr :: Expr Bool -> Expr Bool -> Expr Bool
  15.     ExprText :: String -> Expr String
  16.     ExprTextAppend :: Expr String -> Expr String -> Expr String
  17.     ExprObject :: Map String Value -> String -> Expr Value
  18.  
  19. eval :: Expr t -> t
  20. eval (ExprBool value) = value
  21. eval (ExprBoolOr lft rgt) = eval lft || eval rgt
  22. eval (ExprText value) = value
  23. eval (ExprTextAppend lft rgt) = eval lft <> eval rgt
  24. eval (ExprObject map fieldName) = map ! fieldName
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement