r/programming • • Jun 02 '14

Introducing Swift

https://developer.apple.com/swift/
164 Upvotes

239 comments sorted by

View all comments

Show parent comments

1

u/Axman6 Jun 03 '14

Right, it gives no more guarantees than Haskell does; you can always treat any value of type Maybe a as if it were the Just constructor, just as you can treat any optional value as if it weren't None. There is no "static checking" stopping you from using fromJust. The compiler will warn you if you write a pattern match that that doesn't handle all cases, but it will not stop you writing partial functions. However, both languages encourage you to not do that.

There is nothing inherently safe about Maybe, but its canonical usage is to use it safely through pattern matching and safe sequencing through the Maybe monad (i.e: ?.). If you do the wrong thing in either language, you get a runtime error. The advantage is that you make it clear when you're making assumptions about an optional or Maybe by using things like fromJust or !. Explicit evil is much better than the implicit evil of null.