1 import "Prelude" hiding (findFirst)
6 findFirst :: (a -> <e> Maybe b) -> [a] -> <e> Maybe b
12 | otherwise = match f (l!i) with
16 dfsFirst :: (a -> <e> Boolean) -> (a -> <e> [a]) -> [a] -> <e> (Maybe a)
17 dfsFirst acceptable successors initial = tryAll initial
19 tryAll l = findFirst loop l
21 | acceptable p = Just p
22 | otherwise = tryAll (successors p)
24 data Weighted a = Weighted a Double
26 //type SearchAlgorithm e a =
27 // (a -> <e> Boolean) -> (a -> <e> [Weighted a]) -> [Weighted a] -> <e> Weighted (Maybe a)
29 //dfs :: SearchAlgorithm e a
30 dfs :: (a -> <e> Boolean) -> (a -> <e> [Weighted a]) -> [Weighted a] -> <e> Weighted (Maybe a)
31 dfs acceptable successors initial = foldl loop (Weighted Nothing infinity) initial
33 loop best@(Weighted _ bestW) (Weighted p w)
35 | acceptable p = Weighted (Just p) w
36 | otherwise = foldl loop best
37 $ map (\(Weighted p' w') -> Weighted p' (w+w'))
41 bfs :: SearchAlgorithm e a
43 aStar :: (a -> <e> Double) -> SearchAlgorithm e a