Home > Net >  Error in closure function when recursing over the list
Error in closure function when recursing over the list

Time:04-03

I've implemented a function but it doesn't seem to be going deep enough since it's not returning all the possible options.

And this my function and helper:

let closure n lst =
  iterate ( (a, x) -> a into (closure_helper n x)) lst)

I get 6. what am I missing?

CodePudding user response:

Here's your code that determines what states can be reached from q, given a transition (a, b, c) and a list of other transitions t:

if a = q && b = None then 
   (c::(closure_helper delta c)) @ (closure_helper t q)
else
    closure_helper t q

Note that in general delta represents only the transitions not examined yet by closure_helper, not the full list of transitions. Thus when you find a new reachable state c you only look for further states by looking at a subset of the transitions.

So it seems to me.

  • Related