[Haskell-cafe] DFAs and self-referential data

Roman Cheplyaka roma at ro-che.info
Sun Dec 26 12:58:15 CET 2010

* Maxime Henrion <mhenrion at gmail.com> [2010-12-26 12:01:31+0100]
> Anyone knows what I'm doing wrong here?  I suspect my attempt at having
> self-referential data is somehow buggy; do I need to treat transitions
> to the same state differently?

The problem is that when you call 'self', you record *that* state of
your DFA in the map. When DFA gets updated further, the recorded
self-reference is not updated appropriately.

In your case a workaround is to call 'self' after all the other updates,

    test :: String -> Bool
    test = accept s1
      where s1 = self '1' . path '0' s2 $ empty True
            s2 = self '1' . path '0' s1 $ empty False

But I don't see why you need 'self' at all -- you can just use path as
with any other type of transition:

    test :: String -> Bool
    test = accept s1
      where s1 = path '0' s2 . path '1' s1 $ empty True
            s2 = path '0' s1 . path '1' s2 $ empty False

Roman I. Cheplyaka :: http://ro-che.info/
Don't worry what people think, they don't do it very often.

More information about the Haskell-Cafe mailing list