1 -- the read-eval-print loop 2 -- without the eval 3 4 5 module Heuristic 6 7 ( heu 8 ) 9 10 where 11 12 import Options 13 14 import Ids 15 16 import Syntax 17 18 ---------------------------------------------------------------------- 19 20 -- check through a list of operations, 21 -- prepend these to the input 22 heuristic :: Opts -> [ String ] -> Exp -> Exp 23 heuristic opts hs inp = foldr (\ name inp' -> case onoff opts name of 24 True -> App (userfun 1 name) [inp'] 25 False -> inp' 26 ) inp hs 27 28 -- look through the complete tree and insert heuristics after each "=" 29 heureq :: Opts -> [ String ] -> Exp -> Exp 30 heureq opts hs (App id args) | idname id == "=" = 31 let a : as = args 32 in App id (a : map (heuristic opts hs . heureq opts hs) as) 33 heureq opts hs (App id args) = 34 App id (map (heureq opts hs) args) 35 heureq opts hs x = x -- don't change 36 37 -- insert heuristics at each top-level expression that is not an assignment 38 heutop :: Opts -> [ String ] -> Exp -> Exp 39 heutop opts hs (App id args) | idname id == ";" = 40 App id (map (heutop opts hs) args) 41 heutop opts hs x @ (App id args) | idname id == "=" = x -- won't change 42 heutop opts hs x = heuristic opts hs x -- do change 43 44 45 46 heu opts hs = heutop opts hs . heureq opts hs