Skip to content

Commit

Permalink
show off 'box' in the example
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeplus64 committed Dec 15, 2012
1 parent 24411c8 commit 5d6c777
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions src/Example.hs
Expand Up @@ -12,13 +12,21 @@ type Point
op :: Record Point op :: Record Point
op = 0 & 0 & 0 & (0,0,0) & end op = 0 & 0 & 0 & (0,0,0) & end


type User
= '[ "nick" := String
, "real name" := String
, "gender" := String
, "country of birth" := String ]

main :: IO () main :: IO ()
main = do main = do
point <- runcomp newIORef op point <- runcomp newIORef op
-- point :: RecordT IORef Point -- point :: RecordT IORef Point


let pointx = [get|x|] point let pointx, pointy, pointz :: IORef Double
pointy = [get|x|] point pointc :: IORef (Int, Int, Int)
pointx = [get|x|] point
pointy = [get|y|] point
pointz = [get|z|] point pointz = [get|z|] point
pointc = [get|colour|] point pointc = [get|colour|] point


Expand All @@ -29,6 +37,22 @@ main = do


-- "freeze" the record -- "freeze" the record
frozenPoint <- runtrans readIORef point frozenPoint <- runtrans readIORef point
-- frozenPoint :: Record Point -- frozenPoint :: Record Point
print frozenPoint print frozenPoint
-- 0.0 & 1.0 & 2.0 & (255,255,0) & end

let greg :: Record User
greg = "GREG" & "Sir Greg of Gerg" & "Male" & "Gregland" & end

makeSpy :: Record User -> RecordT Maybe User
makeSpy = [set|real name|] Nothing . box Just

print greg
-- "GREG" & "Sir Greg of Gerg" & "Male" & "Gregland" & end

print (makeSpy greg)
-- Just "GREG" & Nothing & Just "Male" & Just "Gregland" & end

print (run (makeSpy greg))
-- Nothing


0 comments on commit 5d6c777

Please sign in to comment.