Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nwtgck/random-access-machine-haskell
Random Access Machine written in Haskell
https://github.com/nwtgck/random-access-machine-haskell
haskell haskell-stack ram random-access-machine stack
Last synced: 21 days ago
JSON representation
Random Access Machine written in Haskell
- Host: GitHub
- URL: https://github.com/nwtgck/random-access-machine-haskell
- Owner: nwtgck
- License: bsd-3-clause
- Created: 2018-04-19T09:42:00.000Z (over 6 years ago)
- Default Branch: develop
- Last Pushed: 2022-01-16T04:30:19.000Z (almost 3 years ago)
- Last Synced: 2024-10-26T17:49:32.410Z (2 months ago)
- Topics: haskell, haskell-stack, ram, random-access-machine, stack
- Language: Haskell
- Homepage:
- Size: 9.77 KB
- 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
# random-access-machine
[![Build Status](https://travis-ci.com/nwtgck/random-access-machine-haskell.svg?token=TuxNpqznwwyy7hyJwBVm&branch=develop)](https://travis-ci.com/nwtgck/random-access-machine-haskell)Random Access Machine written in Haskell
## Instructions
This Random Access Machine has 5 instructions.### `Z(i)`
Set `0` to register `R(i)`### `S(i)`
Increment register `R(i)` by `1`### `M(i,j)`
Assign value of `R(j)` to `R(i)`### `J(i,j,k)`
Jump to `k`th instruction if value of `R(i)` and `R(j)` are equal
(NOTE: instruction is one origin)### `E`
Halt program## Example
```hs
module Main whereimport RandomAccessMachine
import Control.Monad.Statesub1Prog = Program
[ J(1, 2, 5)
, S(2)
, S(0)
, J(0, 0, 1)
, E
]main :: IO ()
main = do
let (res, env) = execProgram sub1Prog [7, 4] -- 7 - 4
print res
-- => 3
let (res, env) = execProgram sub1Prog [87, 23] -- 87 - 23
print res
-- 64
```## Run Example
```bash
stack build && stack exec random-access-machine-examples
```