-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
+import "Prelude" hiding (findFirst)
+
+infinity = 1e9
+
+@inline
+findFirst :: (a -> <e> Maybe b) -> [a] -> <e> 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 -> <e> Boolean) -> (a -> <e> [a]) -> [a] -> <e> (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 -> <e> Boolean) -> (a -> <e> [Weighted a]) -> [Weighted a] -> <e> Weighted (Maybe a)
+
+//dfs :: SearchAlgorithm e a
+dfs :: (a -> <e> Boolean) -> (a -> <e> [Weighted a]) -> [Weighted a] -> <e> 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 -> <e> Double) -> SearchAlgorithm e a
+*/
+main = "Hello"
+--
Hello
\ No newline at end of file