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

[ control, library, mpl ] [ Propose Tags ] [ Report a vulnerability ]

Reflect on Motor FSM typeclasses to obtain runtime representations.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.2.0.0, 0.3.0, 0.4.0
Change log CHANGELOG.md
Dependencies base (>=4.9 && <5), motor (>=0.4.0), template-haskell (>=2.11.1.0), text [details]
License MPL-2.0
Copyright Oskar Wickström
Author Oskar Wickström
Maintainer oskar.wickstrom@gmail.com
Category Control
Source repo head: git clone https://github.com/owickstrom/motor
Uploaded by owickstrom at 2019-06-28T05:58:59Z
Distributions
Reverse Dependencies 1 direct, 1 indirect [details]
Downloads 1789 total (12 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]

motor-reflection

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

This package is experimental!

Usage

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 :: * -> *
  initial
    :: Name n
    -> Actions m '[n !+ State m Open] r ()
  close
    :: Name n
    -> Actions m '[n :-> State m Open !--> State m Closed] r ()
  open
    :: Name n
    -> Actions m '[n :-> State m Closed !--> State m Open] r ()
  end
    :: 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.

Conventions

  • 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.

License

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