@@ -69,13 +69,27 @@ statically =
69
69
\fun = isDigit :: Char -> Bool\n "
70
70
p_ " You have to pass the right type of values to functions, or the compiler\
71
71
\ will reject the program:"
72
- rejectedHaskellPre " Type error" " isDigit 1"
73
- p_ " You can decode bytes into text:"
74
- haskellPre " bytes = Crypto.Hash.SHA1.hash \" hello\" :: ByteString\n \
75
- \text = decodeUtf8 bytes :: Text\n "
76
- p_ " But you cannot decode Text, which is already a vector \
77
- \of Unicode points:"
78
- rejectedHaskellPre " Type error" " doubleDecode = decodeUtf8 (decodeUtf8 bytes)"
72
+ haskellPre " fun char -- typechecks"
73
+ rejectedHaskellPre " Type error" " fun int"
74
+ p_ (do " Notice how the types "
75
+ code_ " Char"
76
+ " and "
77
+ code_ " Char -> Bool"
78
+ " tell you that you can combine those values by applying "
79
+ code_ " fun"
80
+ " to "
81
+ code_ " char"
82
+ " . With more sophisticated types, and with a bit of experience, it's \
83
+ \often possible to use a Haskell library without reading any tutorial, \
84
+ \just by examining the types of the values it exports." )
85
+ p_ " A precise type is also a useful guide when implementing a function."
86
+ haskellPre " mySnd :: (a, b) -> b\n \
87
+ \mySnd (x, y) = _hole"
88
+ p_ (do " Here, the compiler will tell you that you need a value of type "
89
+ code_ " b"
90
+ " to fill the hole, and that among the values which are in scope, "
91
+ code_ " y"
92
+ " is the only one which has the required type." )
79
93
80
94
concurrent :: Html ()
81
95
concurrent =
0 commit comments