-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.hs
42 lines (32 loc) · 816 Bytes
/
Utils.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
module Utils
( checkInterp
, cleanLine
, lookupEnv
, isInEnv
) where
import Data.Maybe
import Parser
import Types
import System.IO
checkEnv :: Env -> Int -> Maybe Interp
checkEnv [] n = Nothing
checkEnv (x:xs) n =
if fst x == n
then Just $ snd x
else checkEnv xs n
isInEnv :: Int -> Env -> Bool
isInEnv n env =
isJust $ checkEnv env (abs n)
lookupEnv :: Env -> Int -> Interp
lookupEnv env n =
if n < 0
then (not . fromJust) $ checkEnv env (abs n)
else fromJust $ checkEnv env n
-- must be complete environment to clean
cleanLine :: Env -> Clause -> Bool
cleanLine env clause =
foldr (||) False (map (lookupEnv env) clause)
checkInterp :: Env -> [Clause] -> Bool
checkInterp env [] = True
checkInterp env (x:xs) =
cleanLine env x && checkInterp env xs