diff --git a/src/Example.hs b/src/Example.hs index 7589830..78b8e79 100644 --- a/src/Example.hs +++ b/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