Skip to content
This repository was archived by the owner on Feb 15, 2025. It is now read-only.

Commit c149cf5

Browse files
committed
initial commit
1 parent 460fb92 commit c149cf5

File tree

7 files changed

+288
-2
lines changed

7 files changed

+288
-2
lines changed

LICENCE

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Copyright Tim Watson, 2012-2013.
2+
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
* Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
11+
* Redistributions in binary form must reproduce the above
12+
copyright notice, this list of conditions and the following
13+
disclaimer in the documentation and/or other materials provided
14+
with the distribution.
15+
16+
* Neither the name of the author nor the names of other
17+
contributors may be used to endorse or promote products derived
18+
from this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,24 @@
1-
# distributed-process-fsm
2-
Cloud Haskell implementation of Erlang's gen_statem (ish)
1+
# distribributed-process-fsm
2+
[![Build Status](https://secure.travis-ci.org/haskell-distributed/distributed-process-fsm.png)](http://travis-ci.org/haskell-distributed/distributed-process-fsm)
3+
[![Code Coverage](https://coveralls.io/repos/github/haskell-distributed/distributed-process-fsm/badge.svg?branch=master)](https://coveralls.io/github/haskell-distributed/distributed-process-fsm?branch=master)
4+
[![BSD3 License](http://img.shields.io/badge/license-BSD3-brightgreen.svg)](https://tldrlegal.com/license/bsd-3-clause-license-%28revised%29)
5+
[![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/haskell-distributed)
6+
7+
### Releases, LTS
8+
Github: [![GitHub tag](https://img.shields.io/github/tag/haskell-distributed/distributed-process-fsm.svg)]() [![GitHub commits](https://img.shields.io/github/commits-since/haskell-distributed/distributed-process-fsm/release-0.0.1.svg)]()
9+
10+
Hackage: [![Releases](https://img.shields.io/hackage/v/distributed-process-fsm.svg)](https://hackage.haskell.org/package/distributed-process-fsm) [![Dependencies](https://img.shields.io/hackage-deps/v/distributed-process-fsm.svg)](http://packdeps.haskellers.com/feed?needle=distributed-process-fsm)
11+
12+
Stackage: [![LTS 6](https://www.stackage.org/package/distributed-process-fsm/badge/lts-6)](http://stackage.org/lts-6/package/distributed-process-fsm)
13+
[![NIGHTLY](https://www.stackage.org/package/distributed-process-fsm/badge/nightly)](http://stackage.org/nightly/package/distributed-process-fsm)
14+
15+
### Getting Help / Raising Issues
16+
[![Slack Sign Up/In](https://rauchg-slackin-dxinpkuzrg.now.sh/badge.svg)](https://rauchg-slackin-dxinpkuzrg.now.sh/) [![Slack Sign Up/In](https://img.shields.io/badge/Freenode-%23haskell--distributed-ff69b4.svg)]()
17+
18+
As well as our Slack channels (you'll need to sign up, but there is a form for doing so) and #haskell-distributed on freenode, you can contact the [email protected] mailing list for help and comments. Please also see http://haskell-distributed.github.com for documentation, user guides, tutorials and assistance.
19+
20+
Visit the [bug tracker](https://github.com/haskell-distributed/distributed-process-client-server/issues) to submit issues.
21+
22+
### License
23+
24+
This package is made available under a 3-clause BSD-style license.

Setup.lhs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env runhaskell
2+
> import Distribution.Simple
3+
> main = defaultMain

distributed-process-fsm.cabal

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: distributed-process-fsm
2+
version: 0.0.1
3+
cabal-version: >=1.8
4+
build-type: Simple
5+
license: BSD3
6+
license-file: LICENCE
7+
stability: experimental
8+
Copyright: Tim Watson 2017
9+
Author: Tim Watson
10+
Maintainer: Tim Watson <[email protected]>
11+
Stability: experimental
12+
Homepage: http://github.com/haskell-distributed/distributed-process-fsm
13+
Bug-Reports: http://github.com/haskell-distributed/distributed-process-fsm/issues
14+
synopsis: The Cloud Haskell implementation of Erlang/OTP gen_statem
15+
description: Modelled after Erlang OTP's gen_statem, this framework provides similar
16+
facilities for Cloud Haskell.
17+
category: Control
18+
Tested-With: GHC==7.10.3 GHC==8.0.1 GHC==8.0.2
19+
data-dir: ""
20+
21+
source-repository head
22+
type: git
23+
location: https://github.com/haskell-distributed/distributed-process-fsm
24+
25+
library
26+
build-depends:
27+
base >= 4.8.2.0 && < 5,
28+
distributed-process >= 0.6.6 && < 0.7,
29+
distributed-process-extras >= 0.3.1 && < 0.4,
30+
distributed-process-async >= 0.2.4 && < 0.3,
31+
distributed-process-client-server >= 0.2.0 && < 0.3,
32+
binary >= 0.6.3.0 && < 0.9,
33+
deepseq >= 1.3.0.1 && < 1.6,
34+
mtl,
35+
containers >= 0.4 && < 0.6,
36+
unordered-containers >= 0.2.3.0 && < 0.3,
37+
stm >= 2.4 && < 2.5,
38+
time > 1.4 && < 1.8,
39+
transformers,
40+
exceptions >= 0.5
41+
extensions: CPP
42+
hs-source-dirs: src
43+
ghc-options: -Wall
44+
exposed-modules:
45+
Control.Distributed.Process.FSM
46+
other-modules:
47+
Control.Distributed.Process.FSM.Internal.Types
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
{-# LANGUAGE ExistentialQuantification #-}
2+
{-# LANGUAGE ScopedTypeVariables #-}
3+
{-# LANGUAGE PatternGuards #-}
4+
{-# LANGUAGE BangPatterns #-}
5+
{-# LANGUAGE RecordWildCards #-}
6+
{-# LANGUAGE TupleSections #-}
7+
{-# LANGUAGE DeriveDataTypeable #-}
8+
{-# LANGUAGE DeriveGeneric #-}
9+
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
10+
{-# LANGUAGE MultiParamTypeClasses #-}
11+
{-# LANGUAGE GADTs #-}
12+
{-# LANGUAGE RankNTypes #-}
13+
14+
module Control.Distributed.Process.FSM where
15+
16+
import Control.Distributed.Process (Process)
17+
import Control.Distributed.Process.Extras
18+
( ExitReason(ExitShutdown)
19+
)
20+
import Control.Distributed.Process.Extras.Time
21+
( TimeInterval
22+
, seconds
23+
)
24+
import Control.Distributed.Process.Serializable (Serializable)
25+
import Control.Monad (void)
26+
import Control.Monad.Fix (MonadFix)
27+
import Control.Monad.IO.Class (MonadIO)
28+
import qualified Control.Monad.State.Strict as ST
29+
( MonadState
30+
, StateT
31+
, get
32+
, lift
33+
, runStateT
34+
)
35+
import Data.Binary (Binary)
36+
import Data.Typeable (Typeable)
37+
import GHC.Generics
38+
39+
data State s d m = State
40+
41+
newtype FSM s d m o = FSM {
42+
unFSM :: ST.StateT (State s d m) Process o
43+
}
44+
deriving ( Functor
45+
, Monad
46+
, ST.MonadState (State s d m)
47+
, MonadIO
48+
, MonadFix
49+
, Typeable
50+
, Applicative
51+
)
52+
53+
data Action = Consume | Produce | Skip
54+
data Transition s m = Remain | PutBack m | Change s
55+
data Event m = Event
56+
57+
data Step s d where
58+
Start :: s -> d -> Step s d
59+
Await :: (Serializable m) => Event m -> Step s d -> Step s d
60+
Always :: FSM s d m (Transition s d) -> Step s d
61+
Perhaps :: (Eq s) => s -> FSM s d m (Transition s d) -> Step s d
62+
Matching :: (m -> Bool) -> FSM s d m (Transition s d) -> Step s d
63+
Sequence :: Step s d -> Step s d -> Step s d
64+
Alternate :: Step s d -> Step s d -> Step s d
65+
Reply :: (Serializable r) => FSM s f m r -> Step s d
66+
67+
type Pipeline = forall s d . Step s d
68+
69+
initState :: forall s d . s -> d -> Step s d
70+
initState = Start
71+
72+
-- endState :: Action -> State
73+
-- endState = undefined
74+
75+
enter :: forall s d m . s -> FSM s d m (Transition s d)
76+
enter = undefined
77+
78+
stopWith :: ExitReason -> Action
79+
stopWith = undefined
80+
81+
event :: (Serializable m) => Event m
82+
event = Event
83+
84+
currentState :: forall s d m . FSM s d m s
85+
currentState = undefined
86+
87+
reply :: forall s d m r . (Serializable r) => FSM s d m r -> Step s d
88+
reply = Reply
89+
90+
timeout :: Serializable a => TimeInterval -> a -> FSM s d m (Transition s d)
91+
timeout = undefined
92+
93+
set :: forall s d m . (d -> d) -> FSM s d m ()
94+
set = undefined
95+
96+
put :: forall s d m . d -> FSM s d m ()
97+
put = undefined
98+
99+
(.|) :: Step s d -> Step s d -> Step s d
100+
(.|) = Alternate
101+
infixr 9 .|
102+
103+
(|>) :: Step s d -> Step s d -> Step s d
104+
(|>) = Sequence
105+
infixr 9 |>
106+
107+
(<|) :: Step s d -> Step s d -> Step s d
108+
(<|) = undefined
109+
infixr 9 <|
110+
111+
(~>) :: forall s d m . (Serializable m) => Event m -> Step s d -> Step s d
112+
(~>) = Await
113+
infixr 9 ~>
114+
115+
(~@) :: forall s d m . (Eq s) => s -> FSM s d m (Transition s d) -> Step s d
116+
(~@) = Perhaps
117+
infixr 9 ~@
118+
119+
allState :: forall s d m . FSM s d m (Transition s d) -> Step s d
120+
allState = Always
121+
122+
(~?) :: forall s d m . (m -> Bool) -> FSM s d m (Transition s d) -> Step s d
123+
(~?) = Matching
124+
125+
start :: Pipeline -> Process ()
126+
start = const $ return ()
127+
128+
data StateName = On | Off deriving (Eq, Show, Typeable, Generic)
129+
instance Binary StateName where
130+
131+
data Reset = Reset deriving (Eq, Show, Typeable, Generic)
132+
instance Binary Reset where
133+
134+
type StateData = Integer
135+
type ButtonPush = ()
136+
type Stop = ExitReason
137+
138+
initCount :: StateData
139+
initCount = 0
140+
141+
startState :: Step StateName Integer
142+
startState = initState Off initCount
143+
144+
demo :: Step StateName StateData
145+
demo = startState
146+
|> (event :: Event ButtonPush)
147+
~> ( (On ~@ (set (+1) >> enter Off))
148+
.| (Off ~@ (set (+1) >> enter On))
149+
) <| (reply currentState)
150+
.| (event :: Event Stop)
151+
~> ((== ExitShutdown) ~? (timeout (seconds 3) Reset))
152+
.| (event :: Event Reset) ~> (allState $ put initCount >> enter Off)
153+
-- .| endState $ stopWith ExitNormal
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{-# LANGUAGE ExistentialQuantification #-}
2+
{-# LANGUAGE ScopedTypeVariables #-}
3+
{-# LANGUAGE PatternGuards #-}
4+
{-# LANGUAGE BangPatterns #-}
5+
{-# LANGUAGE RecordWildCards #-}
6+
{-# LANGUAGE TupleSections #-}
7+
{-# LANGUAGE DeriveDataTypeable #-}
8+
{-# LANGUAGE DeriveGeneric #-}
9+
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
10+
{-# LANGUAGE MultiParamTypeClasses #-}
11+
{-# LANGUAGE Rank2Types #-}
12+
13+
module Control.Distributed.Process.FSM.Internal.Types
14+
where
15+
16+
data Foo = Foo

stack.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
resolver: nightly-2017-02-03
2+
3+
packages:
4+
- '.'
5+
- location:
6+
git: https://github.com/haskell-distributed/distributed-process-client-server.git
7+
commit: 8ad94262693eb66a158dbcd3b3908a2fc0888968
8+
extra-dep: true
9+
10+
extra-deps:
11+
- distributed-process-0.6.6 # missing snapshot
12+
- distributed-process-extras-0.3.1 # missing snapshot
13+
- distributed-process-async-0.2.4 # missing snapshot
14+
- distributed-process-systest-0.1.1 # missing prior to Jan-2017
15+
- rematch-0.2.0.0

0 commit comments

Comments
 (0)