https://github.com/davidar/moded-logic
https://github.com/davidar/moded-logic
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/davidar/moded-logic
- Owner: davidar
- License: bsd-3-clause
- Created: 2021-03-26T03:36:25.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-06-19T07:10:23.000Z (almost 5 years ago)
- Last Synced: 2025-02-09T23:47:59.583Z (over 1 year ago)
- Language: Haskell
- Size: 1.39 MB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog.md
- License: LICENSE
Awesome Lists containing this project
README
# moded-logic
[](https://gitpod.io/#https://github.com/davidar/moded-logic)
[](https://coveralls.io/github/davidar/moded-logic?branch=master)
A Haskell implementation of [Constraint-Based Mode Analysis of Mercury](https://lara.epfl.ch/w/_media/cc09:modeanalysisoverton.pdf), targeting [the Logic monad](https://hackage.haskell.org/package/logict).
## Logic program
```hs
append [] b b.
append (h:t) b (h:tb) :- append t b tb.
```
## Usage
```hs
> observeAll (append_ooi [1..5])
[([],[1,2,3,4,5]),([1],[2,3,4,5]),([1,2],[3,4,5]),([1,2,3],[4,5]),([1,2,3,4],[5]),([1,2,3,4,5],[])]
```
## Code generated by mode analysis
```hs
append_iii a1 a2 a3 = (do
guard $ a1 == []
b <- pure a2
guard $ a3 == b
pure ()
) <|> (do
(h0:t) <- pure a1
b <- pure a2
(h1:tb) <- pure a3
h <- pure h1
guard $ h0 == h
() <- append_iii t b tb
pure ()
)
append_iio a1 a2 = (do
guard $ a1 == []
b <- pure a2
a3 <- pure b
pure (a3)
) <|> (do
(h0:t) <- pure a1
h <- pure h0
h1 <- pure h
b <- pure a2
(tb) <- append_iio t b
a3 <- pure (h1:tb)
pure (a3)
)
append_ooi a3 = (do
a1 <- pure []
b <- pure a3
a2 <- pure b
pure (a1,a2)
) <|> (do
(h1:tb) <- pure a3
h <- pure h1
h0 <- pure h
(t,b) <- append_ooi tb
a1 <- pure (h0:t)
a2 <- pure b
pure (a1,a2)
)
```