import "Prelude" hiding (findFirst) infinity = 1e9 @inline findFirst :: (a -> Maybe b) -> [a] -> Maybe b findFirst f l = loop 0 where len = length l loop i | i >= len = Nothing | otherwise = match f (l!i) with s @ (Just _) -> s Nothing -> loop (i+1) dfsFirst :: (a -> Boolean) -> (a -> [a]) -> [a] -> (Maybe a) dfsFirst acceptable successors initial = tryAll initial where tryAll l = findFirst loop l loop p | acceptable p = Just p | otherwise = tryAll (successors p) data Weighted a = Weighted a Double //type SearchAlgorithm e a = // (a -> Boolean) -> (a -> [Weighted a]) -> [Weighted a] -> Weighted (Maybe a) //dfs :: SearchAlgorithm e a dfs :: (a -> Boolean) -> (a -> [Weighted a]) -> [Weighted a] -> Weighted (Maybe a) dfs acceptable successors initial = foldl loop (Weighted Nothing infinity) initial where loop best@(Weighted _ bestW) (Weighted p w) | w >= bestW = best | acceptable p = Weighted (Just p) w | otherwise = foldl loop best $ map (\(Weighted p' w') -> Weighted p' (w+w')) $ successors p /* bfs :: SearchAlgorithm e a aStar :: (a -> Double) -> SearchAlgorithm e a */ main = "Hello" -- Hello