You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's also possible to do it without the suspensions:
-- converges
some v =(:)<$> v <*> many v
many v =pure[]<|> some v
And it's possible to reintroduce the original issue by adding a suspension:
-- diverges
some v =(:)<$> v <*> many v
many v = suspended (pure[]) <|> some v
This is an issue with left recursion generally, see the note in Oleg's original code:
-- The following code is not in general MonadPlus: it uses Incomplete-- explicitly. But it supports left recursion! Note that in OCaml, for example,-- we _must_ include that Incomplete data constructor to make-- the recursive definition well-formed. -- The code does *not* get stuck in the generation of primitive tuples-- like (0,1,1), (0,2,2), (0,3,3) etc.
pythagorean_triples' =let number = (Incomplete number >>=return.succ) `mplus`return0
I think miniKanren addresses it by liberally adding suspensions (delay/incomplete) everywhere in the higher-level abstractions...
The default definitions of
some
andmany
fail to converge forStream
.It’s possible to come up with definitions of
some
andmany
that work better than the default ones:Though perhaps this indicates a deeper problem with the existing definitions of
<$>
,<*>
, and<|>
?The text was updated successfully, but these errors were encountered: