[Haskell-cafe] State Machine Composition

Nicolas Trangez nicolas at incubaid.com
Wed Dec 21 23:24:19 CET 2011


On Wed, 2011-12-21 at 18:34 +0000, Daniel Waterworth 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

Any way to do something along the lines of

type StateChange a = SC a a

handleChange :: Monad m => StateChange ConnectionState -> m ()
handleChange (SC Closed Opening) = return ()
handleChange (SC Opening Closed) = return ()
handleChange (SC Closed Open) = return ()

where the last line would yield a type checking error at compile time,
and the compiler can warn about handleChange not being exhaustive (for
the valid state change steps)?

Nicolas




More information about the Haskell-Cafe mailing list