Re:Go vs. Swift [pdf]
by GregBuchholz on Thursday January 19, 2017 @12:13AM
(#13433204)
>in Haskell, by default you can't compare an Optional with the value it wraps: `5 == Just 5` fails.
[ Parent
| on HN ]
This only works because you're working with number literals here, which have the very liberal type "Num a => a". If I replace your main function by
check :: Int -> Bool
check x = x == (Just x)
main = print (check 5)
I get a compile error: Main.hs:7:17: error:
• Couldn't match expected type ‘Int’ with actual type ‘Maybe Int’
• In the second argument of ‘(==)’, namely ‘(Just x)’
In the expression: x == (Just x)
In an equation for ‘check’: check x = x == (Just x)
Re:Go vs. Swift [pdf]
by GregBuchholz on Thursday January 19, 2017 @12:36PM
(#13437576)
Right, it was just a fun little "Well Actually" moment.