Created
December 9, 2015 18:50
-
-
Save jtobin/0b173dae5bdc46cf3fa3 to your computer and use it in GitHub Desktop.
A program defined using 'Fix'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE DeriveFunctor #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE StandaloneDeriving #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
data Program f = Running (f (Program f)) | |
deriving instance (Show (f (Program f))) => Show (Program f) | |
data Instruction r = | |
Increment r | |
| Decrement r | |
| Terminate | |
deriving (Functor, Show) | |
increment :: Program Instruction -> Program Instruction | |
increment = Running . Increment | |
decrement :: Program Instruction -> Program Instruction | |
decrement = Running . Decrement | |
terminate :: Program Instruction | |
terminate = Running Terminate | |
program :: Program Instruction | |
program = | |
increment | |
. increment | |
. decrement | |
$ terminate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment