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

Commit e3c2c93

Browse files
committed
Added some failing examples.
1 parent 3ecf94f commit e3c2c93

3 files changed

Lines changed: 21 additions & 7 deletions

File tree

examples/At.purs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,19 @@ module Examples.Control.Lens.At where
1111
foo = SM.fromList ["foo" ~ 2, "bar" ~ 3]
1212

1313
main = do
14+
print "Starting with:"
15+
print foo
1416
print "Removing `foo`"
17+
-- This doesn't compile, as it can't infer the `Maybe Number`.
18+
-- print (foo # at "foo" .~ Nothing)
1519
print (foo # at "foo" .~ (Nothing :: Maybe Number))
1620
print "Inserting `baz`"
1721
print (foo # at "baz" ?~ 5)
22+
print "Inserting `baz` and incrementing"
23+
-- Neither of these compile.
24+
-- This one has an `occurs check` failure.
25+
-- print (foo # at "baz" ?~ 5 # ix "baz" +~ 12)
26+
-- This one doesn't infer the type variable for `MonadState` properly.
27+
-- print (foo #~ do
28+
-- at "baz" ?= 5
29+
-- ix "baz" += 12)

examples/Extend.purs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
module Control.Lens.Examples.Extend where
22

3-
import Control.Lens ((.~), (^.), lens, Lens(), Setter())
3+
import Control.Lens ((.~), (^.), (<#>), lens, Lens(), Setter())
44

55
import Data.Foreign.EasyFFI (unsafeForeignFunction)
66
import Debug.Trace (trace)
77

88
ffi = unsafeForeignFunction
99

1010
fooExt :: forall a r. Setter { | r} {foo :: a | r} Unit a
11-
fooExt = lens (const unit) (ffi ["obj", "x"] "obj.foo = x, obj")
11+
fooExt f o = ffi ["obj", "x"] "obj.foo = x, obj" o <$> f unit
1212

1313
foo :: forall a b r. Lens {foo :: a | r} {foo :: b | r} a b
14-
foo = lens (\o -> o.foo) (\o x -> o{foo = x})
14+
foo f o@{foo = a} = f a <#> \b -> o{foo = b}
1515

1616
main = do
17-
trace $ (fooExt.~"wat") {bar: 3} ^. foo
18-
trace $ ((fooExt.~"wat") {bar: 3}). foo
19-
trace $ {bar: 3}^.fooExt
17+
let bar = {bar: 3}
18+
trace ((bar # fooExt.~"one")^.foo)
19+
trace ((bar # fooExt.~"two").foo)
20+
-- This will not compile.
21+
-- trace $ {bar: 3}^.fooExt

src/Control/Lens/At.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ module Control.Lens.At
8888
instance atSetKKUnit :: (Ord k) => At (S.Set k) k Unit where
8989
at k a2fa setK = go <$> a2fa setK'
9090
where
91-
setK' = if S.member k setK then Just unit else (Nothing :: Maybe Unit)
91+
setK' = if S.member k setK then Just unit else Nothing
9292
go Nothing = maybe setK (const $ S.delete k setK) setK'
9393
go (Just _) = S.insert k setK
9494

0 commit comments

Comments
 (0)