{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RebindableSyntax #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeFamilyDependencies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module Motor.FSM.Class
( MonadFSM(..)
, Name (..)
) where
import Control.Monad.Indexed
import Data.Row.Records
import GHC.OverloadedLabels
import GHC.TypeLits (Symbol)
class IxMonad m => MonadFSM (m :: (Row *) -> (Row *) -> * -> *) where
new :: Name n -> a -> m r (Extend n a r) ()
get :: HasType n a r => Name n -> m r r a
delete :: Name n -> m r (r .- n) ()
enter
:: ( r' ~ (n .== b .// r)
)
=> Name n
-> b
-> m r r' ()
update :: (HasType n a r, Modify n a r ~ r) => Name n -> (a -> a) -> m r r ()
call :: m Empty Empty a -> m r r a
data Name (n :: Symbol) where
Name :: KnownSymbol n => Name n
instance (KnownSymbol n, n ~ n') => IsLabel n (Name n') where
fromLabel = Name :: Name n'