Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.

Commit 8717876

Browse files
committed
Added output to examples.
1 parent b0d165b commit 8717876

5 files changed

Lines changed: 27 additions & 27 deletions

File tree

examples/At.purs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ module Examples.Control.Lens.At where
1212

1313
main = do
1414
print "Starting with:"
15-
print foo
15+
print foo -- fromList [Tuple ("foo") (2),Tuple ("bar") (3)]
1616
print "Removing `foo`"
1717
-- This doesn't compile, as it can't infer the `Maybe Number`.
1818
-- print (foo # at "foo" .~ Nothing)
19-
print (foo # at "foo" .~ (Nothing :: Maybe Number))
19+
print (foo # at "foo" .~ (Nothing :: Maybe Number)) -- fromList [Tuple ("bar") (3)]
2020
print "Inserting `baz`"
21-
print (foo # at "baz" ?~ 5)
21+
print (foo # at "baz" ?~ 5) -- fromList [Tuple ("foo") (2),Tuple ("bar") (3),Tuple ("baz") (5)]
2222
print "Inserting `baz` and incrementing"
2323
-- Neither of these compile.
2424
-- This one has an `occurs check` failure.
25-
-- print (foo # at "baz" ?~ 5 # ix "baz" +~ 12)
25+
-- print (foo # at "baz" ?~ 5 # ix "baz" +~ 12) -- fromList [Tuple ("foo") (2),Tuple ("bar") (3),Tuple ("baz") (17)]
2626
-- This one doesn't infer the type variable for `MonadState` properly.
2727
-- print (foo #~ do
2828
-- at "baz" ?= 5
29-
-- ix "baz" += 12)
29+
-- ix "baz" += 12) -- fromList [Tuple ("foo") (2),Tuple ("bar") (3),Tuple ("baz") (17)]

examples/Each.purs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module Example.Control.Lens.Each where
1+
module Examples.Control.Lens.Each where
22

33
import Control.Lens
44
-- Have to import typeclass because re-exporting doesn't work yet.
@@ -27,7 +27,7 @@ module Example.Control.Lens.Each where
2727
baz = RGBA 0 128 255 1
2828

2929
main = do
30-
print foo
31-
print bar
30+
print foo -- [3,4,5]
31+
print bar -- Tuple (2) (10)
3232
-- Another case of broken inference...
33-
print ((baz # each +~ 10) :: RGBA)
33+
print ((baz # each +~ 10) :: RGBA) -- RGBA (10) (138) (265) (11)

examples/Extend.purs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module Control.Lens.Examples.Extend where
1+
module Examples.Control.Lens.Extend where
22

33
import Control.Lens ((.~), (^.), (<#>), lens, Lens(), Setter())
44

@@ -15,7 +15,7 @@ module Control.Lens.Examples.Extend where
1515

1616
main = do
1717
let bar = {bar: 3}
18-
trace ((bar # fooExt.~"one")^.foo)
19-
trace ((bar # fooExt.~"two").foo)
18+
trace ((bar # fooExt.~"one")^.foo) -- "one"
19+
trace ((bar # fooExt.~"two").foo) -- "two"
2020
-- This will not compile.
2121
-- trace $ {bar: 3}^.fooExt
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module Examples.Nested where
1+
module Examples.Control.Lens.Nested where
22

33
import Control.Lens
44

@@ -28,15 +28,15 @@ module Examples.Nested where
2828

2929
foreign import showFooImpl
3030
"function showFooImpl(foo) {\
31-
\ return JSON.stringify(foo, null, 4);\
31+
\ return JSON.stringify(foo);\
3232
\}" :: forall a. a -> String
3333

3434
main = do
35-
trace $ showFooImpl obj
36-
trace $ showFooImpl $ baz.~10 $ obj
37-
trace $ showFooImpl $ baz.~"wat" $ obj
38-
trace $ showFooImpl $ foo'..bar.~10 $ obj
39-
trace $ showFooImpl $ fooBar+~40 $ obj
40-
trace $ showFooImpl $ obj^.fooBar
41-
trace $ showFooImpl (obj#fooBar%~succ)
42-
trace $ showFooImpl (over (fooBar) succ obj)
35+
trace $ showFooImpl obj -- {"foo":{"bar":0},"baz":true}
36+
trace $ showFooImpl $ baz.~10 $ obj -- {"foo":{"bar":0},"baz":10}
37+
trace $ showFooImpl $ baz.~"wat" $ obj -- {"foo":{"bar":0},"baz":"wat"}
38+
trace $ showFooImpl $ foo'..bar.~10 $ obj -- {"foo":{"bar":10},"baz":true}
39+
trace $ showFooImpl $ fooBar+~40 $ obj -- {"foo":{"bar":40},"baz":true}
40+
trace $ showFooImpl $ obj^.fooBar -- 0
41+
trace $ showFooImpl (obj#fooBar%~succ) -- {"foo":{"bar":1},"baz":true}
42+
trace $ showFooImpl (over (fooBar) succ obj) -- {"foo":{"bar":1},"baz":true}

examples/Tuples.purs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module Examples.Tuples where
1+
module Examples.Control.Lens.Tuples where
22

33
import Control.Lens
44

@@ -7,7 +7,7 @@ module Examples.Tuples where
77
succ x = x + 1
88

99
main = do
10-
print $ ("hello" ~ "world")^._2
11-
print $ (_2.~42) ("hello" ~ "world")
12-
print $ ("hello" ~ "world" ~ "!!!")^._2.._1
13-
print $ over _1 succ (1 ~ 2)
10+
print $ ("hello" ~ "world")^._2 -- "world"
11+
print $ (_2.~42) ("hello" ~ "world") -- Tuple ("hello") (42)
12+
print $ ("hello" ~ "world" ~ "!!!")^._2.._1 -- "world"
13+
print $ over _1 succ (1 ~ 2) -- Tuple (2) (2)

0 commit comments

Comments
 (0)