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