Browse files

show off 'box' in the example

  • Loading branch information...
1 parent 24411c8 commit 5d6c77753aa1860ee3d11499c50d10cb825f59a9 @mikeplus64 committed Dec 15, 2012
Showing with 28 additions and 4 deletions.
  1. +28 −4 src/Example.hs
View
32 src/Example.hs
@@ -12,13 +12,21 @@ type Point
op :: Record Point
op = 0 & 0 & 0 & (0,0,0) & end
+type User
+ = '[ "nick" := String
+ , "real name" := String
+ , "gender" := String
+ , "country of birth" := String ]
+
main :: IO ()
main = do
point <- runcomp newIORef op
- -- point :: RecordT IORef Point
+ -- point :: RecordT IORef Point
- let pointx = [get|x|] point
- pointy = [get|x|] point
+ let pointx, pointy, pointz :: IORef Double
+ pointc :: IORef (Int, Int, Int)
+ pointx = [get|x|] point
+ pointy = [get|y|] point
pointz = [get|z|] point
pointc = [get|colour|] point
@@ -29,6 +37,22 @@ main = do
-- "freeze" the record
frozenPoint <- runtrans readIORef point
- -- frozenPoint :: Record Point
+ -- frozenPoint :: Record Point
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.