Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CoPaR
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Informatik 8
CoPaR
Commits
ed078088
Commit
ed078088
authored
6 years ago
by
Hans-Peter Deifel
Browse files
Options
Downloads
Patches
Plain Diff
random-dfa: Implement coalgebra output format
parent
a5badbb0
No related branches found
No related tags found
No related merge requests found
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/random-dfa/CoalgOutput.hs
+40
-1
40 additions, 1 deletion
src/random-dfa/CoalgOutput.hs
src/random-dfa/DotOutput.hs
+1
-1
1 addition, 1 deletion
src/random-dfa/DotOutput.hs
src/random-dfa/Main.hs
+31
-1
31 additions, 1 deletion
src/random-dfa/Main.hs
with
72 additions
and
3 deletions
src/random-dfa/CoalgOutput.hs
+
40
−
1
View file @
ed078088
module
CoalgOutput
()
where
module
CoalgOutput
(
coalgB
)
where
import
Data.Foldable
(
fold
)
import
Data.List
(
intersperse
)
import
qualified
Data.Text.Lazy.Builder
as
Build
import
qualified
Data.Text.Lazy.Builder.Int
as
Build
import
Lens.Micro.Platform
import
Type
coalgB
::
DFA
->
Build
.
Builder
coalgB
dfa
=
functorB
dfa
<>
"
\n\n
"
<>
transitionsB
dfa
functorB
::
DFA
->
Build
.
Builder
functorB
dfa
=
"{True,False}x(X^"
<>
Build
.
decimal
(
dfa
^.
letters
)
<>
")"
transitionsB
::
DFA
->
Build
.
Builder
transitionsB
dfa
=
foldMap
(
forStateB
dfa
)
[
0
..
dfa
^.
states
-
1
]
forStateB
::
DFA
->
Int
->
Build
.
Builder
forStateB
dfa
n
=
"s"
<>
Build
.
decimal
n
<>
": ("
<>
Build
.
fromString
(
show
(
dfa
^?!
isFinal
.
ix
n
))
<>
", {"
<>
fold
(
intersperse
", "
(
zipWith
successorB
[
0
..
]
(
dfa
^..
transitions
.
ix
n
.
each
))
)
<>
"})
\n
"
successorB
::
Int
->
Int
->
Build
.
Builder
successorB
label
target
=
Build
.
decimal
label
<>
": s"
<>
Build
.
decimal
target
This diff is collapsed.
Click to expand it.
src/random-dfa/DotOutput.hs
+
1
−
1
View file @
ed078088
...
...
@@ -9,7 +9,7 @@ import Lens.Micro.Platform
import
Type
dotB
::
DFA
->
Build
.
Builder
dotB
dfa
=
"digraph {
\n
"
<>
nodesB
dfa
<>
transitionsB
dfa
<>
"}"
dotB
dfa
=
"digraph {
\n
"
<>
nodesB
dfa
<>
transitionsB
dfa
<>
"}
\n
"
nodesB
::
DFA
->
Build
.
Builder
...
...
This diff is collapsed.
Click to expand it.
src/random-dfa/Main.hs
+
31
−
1
View file @
ed078088
...
...
@@ -14,6 +14,7 @@ import Lens.Micro.Platform
import
Type
import
DotOutput
import
CoalgOutput
-- | Generate a random DFA
...
...
@@ -32,9 +33,17 @@ randomDFA s a = do
}
data
OutputFormat
=
Dot
|
MA
instance
Show
OutputFormat
where
show
Dot
=
"dot"
show
MA
=
"ma"
data
Options
=
Options
{
_optStates
::
Int
,
_optLetters
::
Int
,
_optOutputFormat
::
OutputFormat
}
makeLensesWith
abbreviatedFields
''Options
...
...
@@ -50,6 +59,23 @@ options =
OptParse
.
auto
(
OptParse
.
metavar
"M"
<>
OptParse
.
help
"Size of the alphabet"
)
)
<*>
(
OptParse
.
option
readFormat
(
OptParse
.
long
"output-format"
<>
OptParse
.
metavar
"FORMAT"
<>
OptParse
.
value
MA
<>
OptParse
.
help
"Syntax used for the output. Posible values are 'ma' or 'dot'."
<>
OptParse
.
showDefault
)
)
readFormat
::
OptParse
.
ReadM
OutputFormat
readFormat
=
OptParse
.
maybeReader
$
\
case
"ma"
->
Just
MA
"dot"
->
Just
Dot
_
->
Nothing
main
::
IO
()
...
...
@@ -62,7 +88,11 @@ main = do
)
)
let
builder
=
case
opts
^.
outputFormat
of
MA
->
coalgB
Dot
->
dotB
dfa
<-
randomDFA
(
opts
^.
states
)
(
opts
^.
letters
)
TL
.
putStr
Ln
(
Build
.
toLazyText
(
dotB
dfa
))
TL
.
putStr
(
Build
.
toLazyText
(
builder
dfa
))
return
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment