Created
April 26, 2022 16:20
-
-
Save gabejohnson/c5ca279e567fe2c632f1db221de824db to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type FooBar = { foo :: String , bar? :: Int } | |
r :: FooBar | |
r = { foo: "foo" } | |
foo :: String | |
foo = r.foo -- "foo" | |
bar :: Maybe Int | |
bar = r.bar -- Nothing | |
r1 :: FooBar | |
r1 = { foo: "foo", bar: 0 } -- Same as current behavior | |
bar1 :: Maybe Int | |
bar1 = r.bar -- Just 0 | |
r2 :: FooBar | |
r2 = { foo: "foo", bar:? Just 0 } -- :? absorbs the Maybe | |
bar2 :: Maybe Int | |
bar2 = r.bar -- Just 0 | |
bool2 = r1 == r2 -- true | |
r3 :: FooBar | |
r3 = { foo: "foo", bar:? Nothing } -- :? absorbs the Maybe | |
bar3 :: Maybe Int | |
bar3 = r.bar -- Nothing | |
bool3 = r == r3 -- true | |
r4 :: FooBar | |
r4 = r { bar = 0 } -- Same as current behavior | |
bar4 :: Maybe Int | |
bar4 = r4.bar -- Just 0 | |
r5 :: FooBar | |
r5 = r { bar =? Just 0 } -- =? absorbs the Maybe | |
bar5 :: Maybe Int | |
bar5 = r5.bar -- Just 3 | |
r6 :: FooBar | |
r6 = r { bar =? Nothing } -- =? absorbs the Maybe | |
bar6 :: Maybe Int | |
bar6 = r6.bar -- Nothing | |
r7 = { foo: "foo", bar: Just 0 } -- { foo :: String, bar: Maybe Int } | |
bar7 :: Maybe Int | |
bar7 = r7.bar -- Just 0 | |
r8 = { foo: "foo", bar:? Just 0 } -- { foo :: String, bar?: Int } | |
bar8 :: Maybe Int | |
bar8 = r8.bar -- Just 0 | |
let | |
{ foo, bar } = r8 | |
in | |
{ foo, bar? } :: FooBar | |
let | |
{ foo, bar } = r8 | |
in | |
{ foo, bar } :: { foo :: String, bar :: Maybe Int } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment