-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTape.hs
More file actions
22 lines (16 loc) · 768 Bytes
/
Tape.hs
File metadata and controls
22 lines (16 loc) · 768 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module Tape(Cell(..), Tape(..)) where
import Data.List
data Cell = Cell { cell_value :: String }
data Tape = Tape { tape_cells :: [Cell] }
instance Show (Cell) where
show cell = top ++"\n"++ middle ++"\n"++ bottom
where middle = "| " ++ cell_value cell ++ " |"
top = replicate (length middle) '-'
bottom = top
instance Show (Tape) where
show tape = top ++"\n"++ middle ++"\n"++ bottom
where middle = "| " ++ (joinValues tape) ++ " |"
joinValues m = foldl (++) "" $ barred_values $ tape_cells m
barred_values d = intersperse " | " $ map cell_value d
top = replicate (length middle) '-'
bottom = top