Changeset 25
- Timestamp:
- 02/13/05 19:15:26 (4 years ago)
- svk:copy_cache_prev:
- 1041
- Location:
- src
- Files:
-
- 11 modified
-
AST.hs (modified) (11 diffs)
-
Bind.hs (modified) (3 diffs)
-
Eval.hs (modified) (9 diffs)
-
Internals.hs (modified) (3 diffs)
-
Junc.hs (modified) (1 diff)
-
Lexer.hs (modified) (2 diffs)
-
Main.hs (modified) (2 diffs)
-
Parser.hs (modified) (11 diffs)
-
Pretty.hs (modified) (1 diff)
-
Prim.hs (modified) (4 diffs)
-
Shell.hs (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST.hs
r18 r25 14 14 module AST where 15 15 import Internals 16 17 16 import Context 18 17 19 18 type Ident = String 20 21 instance Show (a -> b) where22 show f = "sub { ... }"23 19 24 20 class Context n where … … 53 49 instance Context VBool where 54 50 castV = VBool 55 doCast (VJunc j l) = juncToBool j l51 doCast (VJunc j) = juncToBool j 56 52 doCast (VBool b) = b 57 53 doCast VUndef = False … … 64 60 doCast _ = True 65 61 66 juncToBool :: JuncType -> Set Val -> Bool 67 juncToBool JAny = (True `elementOf`) . mapSet vCast 68 juncToBool JAll = not . (False `elementOf`) . mapSet vCast 69 juncToBool JNone = not . (True `elementOf`) . mapSet vCast 70 juncToBool JOne = (1 ==) . length . filter vCast . setToList 62 juncToBool :: VJunc -> Bool 63 juncToBool (Junc JAny _ vs) = (True `elementOf`) $ mapSet vCast vs 64 juncToBool (Junc JAll _ vs) = not . (False `elementOf`) $ mapSet vCast vs 65 juncToBool (Junc JNone _ vs) = not . (True `elementOf`) $ mapSet vCast vs 66 juncToBool (Junc JOne ds vs) 67 | (True `elementOf`) $ mapSet vCast ds 68 = False 69 | otherwise 70 = (1 ==) . length . filter vCast $ setToList vs 71 71 72 72 instance Context VInt where … … 125 125 vCast x = MkArray (vCast x) 126 126 127 {- 127 128 instance Context VJunc where 128 castV = VJunc JAny 129 vCast x = mkSet (vCast x) 129 castV = JAny . castV 130 vCast x = JAny $ mkSet (vCast x) 131 -} 130 132 131 133 instance Context VList where … … 134 136 vCast (VPair k v) = [k, v] 135 137 vCast (VRef v) = vCast v 138 vCast (VUndef) = [] 136 139 vCast v = [v] 137 140 … … 146 149 147 150 type VScalar = Val 148 type VJunc = Set Val151 -- type VJunc = Set Val 149 152 150 153 instance Context VScalar where … … 204 207 | VSub VSub 205 208 | VBlock Exp 206 | VJunc JuncTypeVJunc209 | VJunc VJunc 207 210 | VError VStr Exp 211 deriving (Show, Eq, Ord) 212 213 data VJunc = Junc { juncType :: JuncType 214 , juncDup :: Set Val 215 , juncSet :: Set Val 216 } deriving (Show, Eq, Ord) 217 218 data JuncType = JAny | JAll | JNone | JOne 208 219 deriving (Show, Eq, Ord) 209 220 … … 226 237 data VSub = Sub 227 238 { isMulti :: Bool 239 , subName :: String 228 240 , subType :: SubType 241 , subPad :: Symbols 229 242 , subAssoc :: String 230 243 , subParams :: Params … … 239 252 | THash Val 240 253 254 {- 241 255 data JuncType = JAll | JAny | JOne | JNone 242 256 deriving (Show, Eq, Ord) 243 244 instance Eq (Env -> [Val] -> Val) 245 instance Ord ( Env -> [Val] ->Val) where257 -} 258 259 instance Ord ([Val] -> StateEnv Val) where 246 260 compare _ _ = LT 247 261 instance (Ord a) => Ord (Set a) where … … 257 271 = App String [Exp] [Exp] 258 272 | Syn String [Exp] 259 | Prim (Env -> [Val] -> Val) 273 | Sym Scope Var 274 | Prim ([Val] -> StateEnv Val) 260 275 | Val Val 261 276 | Var Var SourcePos … … 311 326 defaultScalarParam = buildParam "" "*" "$_" (Val VUndef) 312 327 313 data Env = Env { cxt :: Cxt 314 , sym :: Symbols 315 , cls :: ClassTree 316 , evl :: Env -> Exp -> Val 317 } deriving (Show) 318 type Symbol = (String, Val) 328 -- The eval monad! 329 type StateEnv a = State Env a 330 331 data Env = Env { envContext :: Cxt 332 , envPad :: Symbols 333 , envClasses :: ClassTree 334 , envEval :: Exp -> Eval Val 335 , envCC :: Val -> Eval Val 336 , envBody :: Exp 337 , envDepth :: Int 338 , envID :: Unique 339 } deriving (Show, Eq) 340 319 341 type Symbols = [Symbol] 320 342 data Symbol = Symbol { symScope :: Scope 343 , symName :: String 344 , symValue :: Val 345 } deriving (Show, Eq, Ord) 346 347 data Scope = SGlobal | SMy | SOur | SLet | STemp | SState 348 deriving (Show, Eq, Ord, Read, Enum) 349 350 type Eval x = ContT Val (ReaderT Env IO) x -
src/Bind.hs
r12 r25 44 44 bindArray :: [Exp] -> [Param] -> MaybeError [(Param, Exp)] 45 45 bindArray vs ps = do 46 case foldM (doBindArray (Syn " &infix:," vs)) ([],0) prms of46 case foldM (doBindArray (Syn "," vs)) ([],0) prms of 47 47 Left errMsg -> fail errMsg 48 48 Right (bound,_) -> return $ reverse bound … … 51 51 52 52 doSlice :: Exp -> [VInt] -> Exp 53 doSlice v ns = Syn " &infix:[]" [v, Val $ VList $ map VInt ns]53 doSlice v ns = Syn "[]" [v, Val $ VList $ map VInt ns] 54 54 55 55 -- XXX - somehow force failure 56 56 doIndex :: Exp -> VInt -> Exp 57 doIndex v n = Syn " &infix:[]" [v, Val $ VInt n]57 doIndex v n = Syn "[]" [v, Val $ VInt n] 58 58 59 59 doBindArray :: Exp -> ([(Param, Exp)], VInt) -> (Param, Char) -> MaybeError ([(Param, Exp)], VInt) … … 69 69 70 70 isPair :: Exp -> Bool 71 isPair (Syn " &infix:=>" [(Val v), _]) = True71 isPair (Syn "=>" [(Val v), _]) = True 72 72 isPair (Val (VPair _ _)) = True 73 73 isPair _ = False 74 74 75 75 unPair :: Exp -> (String, Exp) 76 unPair (Syn " &infix:=>" [(Val k), exp]) = (vCast k, exp)76 unPair (Syn "=>" [(Val k), exp]) = (vCast k, exp) 77 77 unPair (Val (VPair k v)) = (vCast k, Val v) 78 78 unPair x = error ("Not a pair: " ++ show x) -
src/Eval.hs
r21 r25 20 20 import Prim 21 21 import Context 22 23 emptyEnv = Env { cxt = "List" 24 , sym = initSyms 25 , cls = initTree 26 , evl = evaluate 22 import Monad 23 24 emptyEnv = Env { envContext = "List" 25 , envPad = [initSyms] 26 , envClasses = initTree 27 , envEval = evaluate 27 28 } 28 29 29 addSym :: Env -> [(String, Val)] -> Env 30 addSym env [] = env 31 addSym env ((var, val):vs) = env{ sym = (var, val):(sym $ addSym env vs) } 32 33 evaluate :: Env -> Exp -> Val 34 evaluate env@Env{ cxt = cxt, cls = cls } exp 35 | Val v <- val = v 36 | otherwise = VError "Invalid expression" exp 37 where 38 (env', val) = reduce env exp 39 isaContext = isaType cls cxt 30 addSym :: Symbols -> StateEnv () 31 addSym syms = modify doAddSyms 32 where 33 doAddSyms env@Env{ envPad = (pad:outer) } = env{ envPad = ((syms++pad):outer) } 34 35 pushPad :: Symbols -> StateEnv () 36 pushPad syms = modify (\env -> env{ envPad = tail $ envPad env }) 37 38 popPad :: StateEnv () 39 popPad = modify (\env -> env{ envPad = tail $ envPad env }) 40 41 evaluate :: Exp -> StateEnv Val 42 evaluate exp = do 43 val <- reduce exp 44 return $ case val of 45 Val v -> v 46 otherwise -> VError "Invalid expression" exp 40 47 41 48 -- OK... Now let's implement the hideously clever autothreading algorithm. … … 43 50 -- Second pass - thread thru any() and one() 44 51 45 chainFun :: Params -> Exp -> Params -> Exp -> Env -> [Val] ->Val46 chainFun p1 f1 p2 f2 env' (v1:v2:vs)47 | VBool False <- applyFun env'(chainArgs p1 [v1, v2]) f148 = VBool False49 | otherwise50 = applyFun env'(chainArgs p2 (v2:vs)) f252 chainFun :: Params -> Exp -> Params -> Exp -> [Val] -> StateEnv Val 53 chainFun p1 f1 p2 f2 (v1:v2:vs) = do 54 val <- applyFun (chainArgs p1 [v1, v2]) f1 55 case val of 56 VBool False -> return val 57 _ -> applyFun (chainArgs p2 (v2:vs)) f2 51 58 where 52 59 chainArgs prms vals = map chainArg (prms `zip` vals) 53 60 chainArg (p, v) = ApplyArg (paramName p) v False 54 61 55 applyFun :: Env -> [ApplyArg] -> Exp -> Val 56 applyFun env bound (Prim f) 57 = f env [ argValue arg | arg <- bound, (argName arg !! 1) /= '_' ] 58 applyFun env bound body 59 | Val val <- exp = val 60 | otherwise = VError "Invalid expression" exp 61 where 62 (fenv, exp) = reduce (env `addSym` formal) body 63 formal = filter (not . null . fst) $ map argNameValue bound 64 argNameValue (ApplyArg name val _) = (name, val) 65 66 apply :: Env -> VSub -> [Exp] -> [Exp] -> ((Env -> Env), Exp) 67 apply env@Env{ cls = cls } Sub{ subParams = prms, subFun = fun } invs args = 62 applyFun :: [ApplyArg] -> Exp -> StateEnv Val 63 applyFun bound (Prim f) 64 = f [ argValue arg | arg <- bound, (argName arg !! 1) /= '_' ] 65 applyFun bound body = do 66 pushPad formal 67 exp <- reduce body 68 return $ case exp of 69 Val val -> val 70 otherwise -> VError "Invalid expression" exp 71 where 72 formal = filter (not . null . symName) $ map argNameValue bound 73 argNameValue (ApplyArg name val _) = Symbol SMy name val 74 75 apply :: VSub -> [Exp] -> [Exp] -> StateEnv Exp 76 apply sub invs args = do 77 env <- get 78 doApply env sub invs args 79 80 doApply :: Env -> VSub -> [Exp] -> [Exp] -> StateEnv Exp 81 doApply env@Env{ envClasses = cls } Sub{ subParams = prms, subFun = fun } invs args = 68 82 case bindParams prms invs args of 69 83 Left errMsg -> retVal $ VError errMsg (Val VUndef) 70 Right bindings -> retVal $ juncApply eval (reverse . fst $ foldl doBind ([],env) bindings) 71 where 72 eval bound = applyFun env bound fun 84 Right bindings -> retVal $ VUndef -- XXX -- juncApply eval (reverse . fst $ foldl doBind ([],env) bindings) 85 where 86 eval bound = applyFun bound fun 87 {- XXX 73 88 doBind :: ([ApplyArg], Env) -> (Param, Exp) -> ([ApplyArg], Env) 74 doBind (bs, env) (prm@Param{ paramName = name }, exp) 75 = let (val, coll) = expToVal env prm exp in 76 (((ApplyArg name val coll): bs), env `addSym` [(name, val)]) 77 expToVal env Param{ isSlurpy = slurpy, paramContext = cxt } exp 78 = (evalEnv env{ cxt = cxt } exp, slurpy || isCollapsed cxt) 89 doBind (bs, env) (prm@Param{ paramName = name }, exp) = do 90 (val, coll) <- expToVal prm exp 91 (((ApplyArg name val coll): bs), env `addSym` [Symbol SMy name val]) 92 -} 93 expToVal Param{ isSlurpy = slurpy, paramContext = cxt } exp = do 94 val <- evalEnvWithContext cxt exp 95 return (val, (slurpy || isCollapsed cxt)) 79 96 isCollapsed cxt 80 97 | isaType cls "Bool" cxt = True … … 83 100 | otherwise = False 84 101 85 evalEnv env@Env{ evl = f } = f env 102 evalEnv exp = do 103 evl <- gets envEval 104 evl exp 105 106 evalEnvWithContext newCxt exp = do 107 Env{ envContext = cxt, envEval = evl } <- get 108 modify (\env -> env{ envContext = newCxt }) 109 val <- evl exp 110 modify (\env -> env{ envContext = cxt }) 111 return val 86 112 87 113 toGlobal name … … 91 117 | otherwise = name 92 118 93 retVal :: Val -> ((Env -> Env), Exp)94 retVal val = (id, Val val)95 96 isGlobalExp (Syn name _) = name `elem` map ("&infix:" ++)(words ":= ::=")119 retVal :: Val -> StateEnv Exp 120 retVal val = return $ Val val 121 122 isGlobalExp (Syn name _) = name `elem` (words ":= ::=") 97 123 isGlobalExp _ = False 98 124 99 reduce :: Env -> Exp -> ((Env -> Env), Exp) 100 reduce Env{ cxt = cxt } exp@(NonTerm _) 101 | cxt == "Bool" = retVal $ VBool False 102 | cxt == "List" = retVal $ VList [] 103 | cxt == "Array" = retVal $ VArray $ MkArray [] 104 | cxt == "Hash" = retVal $ VHash $ MkHash emptyFM 105 | otherwise = retVal $ VUndef 106 107 reduce env@Env{ sym = sym } exp@(Var var _) 108 | Just val <- lookup var sym 125 findSym :: String -> [Symbols] -> Maybe Val 126 findSym name pad 127 | Just s <- find ((== name) . symName) (concat pad) 128 = Just $ symValue s 129 | otherwise 130 = Nothing 131 132 reduce :: Exp -> StateEnv Exp 133 reduce exp = do 134 env <- get 135 doReduce env exp 136 137 doReduce Env{ envPad = pad } exp@(Var var _) 138 | Just val <- findSym var pad 109 139 = retVal val 110 | Just val <- lookup (toGlobal var) sym140 | Just val <- findSym (toGlobal var) pad 111 141 = retVal val 112 142 | otherwise 113 143 = retVal $ VError ("Undefined variable " ++ var) exp 114 144 115 reduce env@Env{ cxt = cxt } exp@(Syn name exps) 116 | name `isInfix` ";" 117 , [left, right] <- exps 118 , (lead, final) <- buildStatements exps 119 , (env', exp) <- foldl (runStatement "Any") (env, Val VUndef) lead 120 , (env', exp) <- runStatement cxt (env', exp) final 121 = (const env', exp) 122 | name `isInfix` ":=" 123 , [Var var _, exp] <- exps 124 , (fenv, Val val) <- reduce env exp 125 = (combineEnv fenv var val, Val val) 126 | name `isInfix` "::=" 127 , [Var var _, Val val] <- exps 128 = (combineEnv id var val, Val VUndef) 129 | name `isInfix` "=>" 130 , [keyExp, valExp] <- exps 131 , key <- evalEnv env keyExp 132 , val <- evalEnv env valExp 133 = retVal $ VPair key val 134 | name `isInfix` "," 135 = retVal $ VList $ concatMap (vCast . evalEnv env{ cxt = "List" }) exps 136 | name `isInfix` "[]" 137 , (listExp:rangeExp:errs) <- exps 138 , list <- evalEnv env{ cxt = "List" } listExp 139 , range <- evalEnv env{ cxt = "List" } rangeExp 140 , slice <- unfoldr (doSlice errs $ vCast list) (map vCast $ vCast range) 141 = retVal $ VList slice 145 doReduce env@Env{ envContext = cxt } exp@(Syn name exps) = case name of 146 ";" -> do 147 let (lead, final) = buildStatements exps 148 vals <- mapM (evalEnvWithContext "Any") lead 149 -- collect IO values from vals? 150 retVal =<< evalEnv final 151 ":=" -> do 152 let [Var var _, exp] = exps 153 val <- evalEnv exp 154 addSym [Symbol SMy var val] -- XXX scope 155 retVal val 156 "::=" -> do -- XXX wrong 157 let [Var var _, exp] = exps 158 val <- evalEnv exp 159 addSym [Symbol SMy var val] -- XXX scope 160 retVal VUndef 161 "=>" -> do 162 let [keyExp, valExp] = exps 163 key <- evalEnv keyExp 164 val <- evalEnv valExp 165 retVal $ VPair key val 166 "," -> do 167 vals <- mapM (evalEnvWithContext "List") exps 168 retVal $ VList vals 169 "[]" -> do 170 let (listExp:rangeExp:errs) = exps 171 list <- evalEnvWithContext "List" listExp 172 range <- evalEnvWithContext "List" rangeExp 173 let slice = unfoldr (doSlice errs $ vCast list) (map vCast $ vCast range) 174 retVal $ VList slice 175 "gather" -> do 176 val <- evalEnvWithContext "List" exp 177 -- ignore val 178 retVal val 179 _ -> do 180 retVal $ VError "Unknown syntactic construct" exp 142 181 where 143 182 doSlice :: [Exp] -> [Val] -> [VInt] -> Maybe (Val, [VInt]) … … 152 191 buildStatements exps 153 192 | ((Syn name' exps'):rest) <- exps 154 , name' `isInfix`";"193 , name' == ";" 155 194 = buildStatements (exps' ++ rest) 156 195 | (global, local) <- partition isGlobalExp exps 157 196 , stmts <- global ++ local 158 197 = (init stmts, last stmts) 159 runStatement :: Cxt -> (Env, Exp) -> Exp -> (Env, Exp) 160 runStatement cxt (env, (Val val)) exp 161 | VError _ _ <- val 162 = (env, Val val) 163 | NonTerm _ <- exp 164 = (env, Val val) 165 | (fenv, exp) <- reduce env{ cxt = cxt } exp 166 = (fenv env, exp) 167 | otherwise 168 = (env, Val $ VError "Unterminated statement" exp) 169 combineEnv f var val env = (f env) `addSym` [(var, val)] 170 isInfix name s = name == "&infix:" ++ s 171 172 reduce env@Env{ cxt = cxt, cls = cls } exp@(App name invs args) 173 | Just sub <- findSub name 174 = applySub sub invs args 175 | otherwise 176 = retVal $ VError ("No compatible subroutine found: " ++ name) exp 198 199 doReduce env@Env{ envClasses = cls, envContext = cxt, envPad = pad } exp@(App name invs args) = do 200 case findSub name of 201 Just sub -> applySub sub invs args 202 otherwise -> retVal $ VError ("No compatible subroutine found: " ++ name) exp 177 203 where 178 204 applySub sub invs args … … 186 212 | Sub{ subAssoc = "list", subParams = (p:_) } <- sub 187 213 , null invs 188 = apply envsub{ subParams = (length args) `replicate` p } [] args214 = apply sub{ subParams = (length args) `replicate` p } [] args 189 215 -- chain-associativity 190 216 | Sub{ subAssoc = "chain", subFun = fun, subParams = prm } <- sub … … 197 223 | Sub{ subAssoc = "chain", subParams = (p:_) } <- sub 198 224 , null invs 199 = apply envsub{ subParams = (length args) `replicate` p } [] args -- XXX Wrong225 = apply sub{ subParams = (length args) `replicate` p } [] args -- XXX Wrong 200 226 -- normal application 201 227 | otherwise 202 = apply envsub invs args228 = apply sub invs args 203 229 findSub name 204 230 | ((_, sub):_) <- sort (subs name) = Just sub … … 208 234 , fromJust fun 209 235 ) 210 | (( n, val), order) <- sym env`zip` [0..]236 | ((Symbol _ n val), order) <- concat pad `zip` [0..] 211 237 , let sub@(Sub{ subType = subT, subReturns = ret, subParams = prms }) = vCast val 212 , n == name || n == toGlobal name238 , (n ==) `any` [name, toGlobal name] 213 239 , let isGlobal = '*' `elem` n 214 240 , let fun = arityMatch sub (invs ++ args) -- XXX Wrong … … 224 250 deltaFromScalar x = deltaType cls x "Scalar" 225 251 226 reduce env (Parens exp) = reduce envexp227 reduce env other = (id, other) 252 doReduce _ (Parens exp) = reduce exp 253 doReduce _ other = return other 228 254 229 255 arityMatch sub@Sub{ subAssoc = assoc, subParams = prms } args -
src/Internals.hs
r19 r25 15 15 16 16 module Internals ( 17 module Cont, 18 module Data.Dynamic, 19 module Data.Unique, 17 20 module System.Environment, 18 21 module System.Random, 19 22 module System.IO, 20 23 module System.IO.Unsafe, 24 module Control.Monad.RWS, 21 25 module Control.Monad.Error, 22 26 module Data.Bits, … … 38 42 ) where 39 43 44 import Cont 45 import Data.Dynamic 40 46 import System.Environment 41 47 import System.Random 42 48 import System.IO hiding (try) 43 49 import System.IO.Unsafe 44 import Control.Monad.Error 50 import Control.Monad.RWS 51 import Control.Monad.Error (MonadError(..)) 45 52 import qualified System.IO (try) 46 import Data.Bits 53 import Data.Bits hiding (shift) 47 54 import Data.Maybe 48 55 import Data.Either 49 56 import Data.List hiding (intersect, union) 57 import Data.Unique 50 58 import Data.Ratio 51 59 import Data.Word … … 57 65 import Data.Tree 58 66 import Debug.Trace 59 import Text.ParserCombinators.Parsec 67 import Text.ParserCombinators.Parsec hiding (parse) 60 68 import Text.ParserCombinators.Parsec.Expr 61 69 import Text.ParserCombinators.Parsec.Error hiding (ParseError, errorPos) 62 70 import Text.ParserCombinators.Parsec.Language 71 72 -- Instances. 73 instance Show Unique where 74 show = show . hashUnique 75 instance Show (a -> b) where 76 show f = "sub { ... }" 77 instance Eq (a -> b) where 78 _ == _ = False -
src/Junc.hs
r18 r25 16 16 opJuncAll = opJunc JAll 17 17 opJuncAny = opJunc JAny 18 opJuncOne vals19 | length (nub vals) == length vals20 = VJunc JOne $ mkSet vals21 | otherwise22 = VJunc JOne emptySet18 opJuncOne args = VJunc (Junc JOne dups vals) 19 where 20 vals = mkSet [ v | [v] <- groups ] 21 dups = mkSet [ v | (v:_:_) <- groups ] 22 groups = group $ sort args 23 23 24 24 opJunc :: JuncType -> [Val] -> Val 25 opJunc j vals = VJunc j $ joined `union` mkSet vs25 opJunc t vals = VJunc $ Junc t emptySet (joined `union` mkSet vs) 26 26 where 27 joined = unionManySets $ map juncValuesjs27 joined = unionManySets $ map (\(VJunc s) -> juncSet s) js 28 28 (js, vs) = partition sameType vals 29 sameType (VJunc j' _) = (j == j')30 sameType _ = False29 sameType (VJunc (Junc t' _ _)) = t == t' 30 sameType _ = False 31 31 32 juncValues :: Val -> VJunc 33 juncValues (VJunc _ l) = l 34 juncValues _ = emptySet 35 36 juncType :: Val -> Maybe (JuncType, VJunc) 37 juncType v 38 | VJunc j l <- v 39 = Just (j, l) 32 juncTypeIs :: Val -> [JuncType] -> Maybe VJunc 33 juncTypeIs v ts 34 | (VJunc j) <- v 35 , juncType j `elem` ts 36 = Just j 40 37 | otherwise 41 38 = Nothing 42 39 43 juncTypeIs :: Val -> [JuncType] -> Maybe (JuncType, VJunc) 44 juncTypeIs v js 45 | Just (j, l) <- juncType v 46 , j `elem` js 47 = Just (j, l) 48 | otherwise 49 = Nothing 50 40 mergeJunc j ds vs 41 | j == JAny = Junc j (mkSet ds) (mkSet vs) 42 | j == JOne = Junc j dups vals 43 where 44 vals = mkSet [ v | [v] <- group $ sort vs ] 45 dups = mkSet (ds ++ [ v | (v:_:_) <- group $ sort (vs ++ ds) ]) 51 46 52 47 juncApply f args 53 | (before, (ApplyArg name (VJunc j vs) coll):after) <- break isTotalJunc args 54 = VJunc j $ mapSet (\v -> juncApply f (before ++ ((ApplyArg name v coll):after))) vs 55 | (before, (ApplyArg name (VJunc j vs) coll):after) <- break isPartialJunc args 56 = VJunc j $ mapSet (\v -> juncApply f (before ++ ((ApplyArg name v coll):after))) vs 48 | this@(_, (pivot:_)) <- break isTotalJunc args 49 , VJunc (Junc j dups vals) <- argValue pivot 50 = VJunc $ Junc j dups $ appSet this vals 51 | this@(_, (pivot:_)) <- break isPartialJunc args 52 , VJunc (Junc j dups vals) <- argValue pivot 53 = VJunc $ mergeJunc j (appList this dups) (appList this vals) 57 54 | (val:_) <- [ val | (ApplyArg _ val@(VError _ _) _) <- args ] 58 55 = val 59 56 | otherwise 60 57 = f args 58 where 59 appSet x y = mkSet $ appList x y 60 appList (before, (ApplyArg name _ coll):after) vs 61 = map (\v -> juncApply f (before ++ ((ApplyArg name v coll):after))) $ setToList vs 61 62 62 isTotalJunc (ApplyArg _ (VJunc JAll _) b) = not b 63 isTotalJunc (ApplyArg _ (VJunc JNone _) b) = not b 64 isTotalJunc _ = False 63 isTotalJunc arg 64 | (ApplyArg _ (VJunc j) b) <- arg 65 , (juncType j ==) `any` [JAll, JNone] 66 = not b 67 | otherwise 68 = False 65 69 66 isPartialJunc (ApplyArg _ (VJunc JOne _) b) = not b 67 isPartialJunc (ApplyArg _ (VJunc JAny _) b) = not b 68 isPartialJunc _ = False 69 70 isPartialJunc arg 71 | (ApplyArg _ (VJunc j) b) <- arg 72 , (juncType j ==) `any` [JOne, JAny] 73 = not b 74 | otherwise 75 = False 70 76 71 77 data ApplyArg = ApplyArg -
src/Lexer.hs
r9 r25 12 12 modu
