Add an initial 'lazy list' for doing backtracking

Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
This commit is contained in:
Danila Fedorin 2023-11-25 23:33:48 -08:00
parent ed34302627
commit 2cc1012a09

25
src/Bergamot/Search.elm Normal file
View File

@ -0,0 +1,25 @@
module Bergamot.Search exposing (..)
type SearchStep a
= Empty
| Found a (Search a)
type alias Search a = () -> SearchStep a
map : (a -> b) -> Search a -> Search b
map f s () =
case s () of
Empty -> Empty
Found a sp -> Found (f a) (map f sp)
interleave : Search a -> Search a -> Search a
interleave s1 s2 () =
case s1 () of
Empty -> s2 ()
Found a s1p -> Found a (interleave s2 s1p)
one : Search a -> Maybe (a, Search a)
one s =
case s () of
Empty -> Nothing
Found a sp -> Just (a, sp)