register-machine-typelevel-0.1.0.0: A computationally universal register machine implementation at the type-level

Copyright(C) 2016 Csongor Kiss
LicenseBSD3
MaintainerCsongor Kiss <kiss.csongor.kiss@gmail.com>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellSafe
LanguageHaskell2010

Data.Type.Zipper

Description

The list zipper data structure with a focused element (at the type-level).

Used for storing the registers and the instructions because of its performance benefits.

Synopsis

Documentation

data Zipper a where Source

Polymorphic list zipper.

Some functions that operate on Zippers are partial. Instead of having to mess with promoted Maybes and whatnot, this constructor represent an erroneous operation.

Constructors

Zip :: [a] -> a -> [a] -> Zipper a 
Invalid :: Zipper a 

type family FromList xs :: Zipper k Source

Construct `Zipper a` from `[a]`. The list must contain at least one element for the Zipper to be valid. The resulting Zipper focuses on the first element of the list, the tail of the list is found to the right.

Equations

FromList `[]` = Invalid 
FromList (x : xs) = Zip `[]` x xs 

type family Extract zipper :: k Source

Extract the focused element.

Equations

Extract (Zip p c n) = c 

type family Replace zipper with :: Zipper k Source

Replace the focused element with a new one.

Equations

Replace (Zip p c n) with = Zip p with n 

type family ToList zipper :: [k] Source

Create a list from the Zipper by appending together the left lift, the focused element and the right list in this order.

Equations

ToList (Zip `[]` e n) = e : n 
ToList (Zip (p : ps) e n) = ToList (Zip ps p (e : n)) 

type family Left by zipper :: Zipper k Source

Shift the focus to the left

Equations

Left 0 z = z 
Left n (Zip (p : prevs) cur next) = Left (n - 1) (Zip prevs p (cur : next)) 
Left n z = Invalid 

type family Right by zipper :: Zipper k Source

Shift the focus to the right

Equations

Right 0 z = z 
Right by (Zip prevs cur (n : next)) = Right (by - 1) (Zip (cur : prevs) n next) 
Right n z = Invalid