Daniel Waterworth <da.waterwo...@gmail.com> wrote: > I made this simple state machine combinator library today. I think it > works as a simple example of a good use for GADTs. > > https://gist.github.com/1507107
Aren't your examples all special cases of the generic automaton arrow? There are two ways to represent it, both with their advantages and disadvantages: newtype Auto a b = Auto (a -> (b, Auto a b)) countFrom :: Int -> Auto a Int countFrom n = Auto (\_ -> (n, countFrom (succ n))) or: data Auto a b = forall s. Auto s ((a, s) -> (b, s)) countFrom :: Int -> Auto a Int countFrom n0 = Auto n0 (\(_, s) -> (s, succ s)) These state machines have local state and can be composed using applicative and arrow interfaces: liftA2 (+) (countFrom 3) (countFrom 5) proc x -> do n1 <- countFrom 10 -< () n2 <- someOtherMachine -< x anotherMachine -< n1 + n2 Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://ertes.de/
signature.asc
Description: PGP signature
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe