motor-reflection: Reflect on Motor FSM typeclasses to obtain runtime representations

[ control, library, mpl ] [ Propose Tags ]

Reflect on Motor FSM typeclasses to obtain runtime representations.

[Skip to Readme]


Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Versions [RSS], 0.3.0, 0.4.0
Change log
Dependencies base (>=4.9 && <5), motor (>=0.4.0), template-haskell (>=, text [details]
License MPL-2.0
Copyright Oskar Wickström
Author Oskar Wickström
Category Control
Source repo head: git clone
Uploaded by owickstrom at 2019-06-28T05:58:59Z
Reverse Dependencies 1 direct, 1 indirect [details]
Downloads 1737 total (8 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for motor-reflection-0.4.0

[back to package description]


Reflect on typeclasses following Motor FSM conventions, using Template Haskell.

This package is experimental!


First, you need to import the reflection module and the Event type:

import           Motor.FSM.Reflection
import           Motor.FSM.Reflection.Event (Event)

Given that your FSM typeclass follows Motor's conventions, you can reflect to get a list of events:

data Open
data Closed

class MonadFSM m => Door (m :: Row * -> Row * -> * -> *) where
  type State m :: * -> *
    :: Name n
    -> Actions m '[n !+ State m Open] r ()
    :: Name n
    -> Actions m '[n :-> State m Open !--> State m Closed] r ()
    :: Name n
    -> Actions m '[n :-> State m Closed !--> State m Open] r ()
    :: Name n
    -> Actions m '[n !- State m Closed] r ()

reflectEvents ''Door "doorEvents"

The last line, using reflectEvents, will define doorEvents :: [Motor.FSM.Reflection.Event.Event] at the top-level.


  • The typeclass must have an associated type (open type family) called State, parameterized by the instance, with a result of kind * -> *.
  • Each FSM event in the typeclass must have a return type of the Actions type alias, listing the additions, deletions, and transitions of named resources.

These conventions may be relaxed in the future. This package is new and experimental.


Mozilla Public License Version 2.0, see LICENSE file in each package.