module Lambda where import Data.List (union, intersect) import Data.Char (chr, ord) data…
- User
module Lambda where
import Data.List (union, intersect) import Data.Char (chr, ord)
data Lambda = Var String | App Lambda Lambda | Abs String Lambda | Macro String
instance Show Lambda where show (Var x) = x show (App e1 e2) = "(" ++ show e1 ++ " " ++ show e2 ++ ")" show (Abs x e) = "L" ++ x ++ "." ++ show e show (Macro x) = x
-- λ
instance Eq Lambda where e1 == e2 = eq e1 e2 ([],[],[]) where eq (Var x) (Var y) (env,xb,yb) = elem (x,y) env || (not $ elem x xb || elem y yb) eq (App e1 e2) (App f1 f2) env = eq e1 f1 env && eq e2 f2 env eq (Abs x e) (Abs y f) (env,xb,yb) = eq e f ((x,y):env,x:xb,y:yb) eq (Macro x) (Macro y) _ = x == y eq _ _ _ = False
-- 1.1. vars :: Lambda -> [String] vars l = case l of Var x -> [x] App e1 e2 -> vars e1
unionvars e2 Abs x e -> [x]unionvars e Macro x -> [x]-- 1.2. freeVarsHelper :: Lambda -> [String] -> [String] freeVarsHelper l lst = case l of Var x -> if x
elemlst then [] else [x] App e1 e2 -> freeVarsHelper e1 lstunionfreeVarsHelper e2 lst Abs x e -> freeVarsHelper e (x : lst) Macro x -> if xelemlst then [] else [x]freeVars :: Lambda -> [String] freeVars l = freeVarsHelper l []
bondedVars :: Lambda -> [String] bondedVars l = filter (
notElemfreeVars l) (vars l)-- 1.3. nextString :: String -> String nextString s | null s = ['a'] | last s == 'z' = nextString (init s) ++ ['a'] | otherwise = init s ++ [nextChar (last s)] where nextChar ch = chr (ord ch + 1)
newVarHelper :: String -> [String] -> String newVarHelper s lst = if s
elemlst then newVarHelper (nextString s) lst else snewVar :: [String] -> String newVar = newVarHelper ['a']
-- 1.4. isNormalForm :: Lambda -> Bool isNormalForm l = case l of App e1 e2 -> case e1 of Abs _ _ -> False _ -> isNormalForm e1 && isNormalForm e2 Abs _ e -> isNormalForm e _ -> True
-- 1.5. changeVar :: Lambda -> String -> [String] -> Lambda changeVar l s lst = case l of Var x -> if x == s then Var newVar lst else Var x
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.