Skip to content

Commit 08b77c4

Browse files
committed
Clarify how to use types for more than validation
The "Statically typed" paragraph mentions that type are "not only a form of guarantee", but the examples did not reflect that.
1 parent 2348fa3 commit 08b77c4

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/HL/View/Home/Features.hs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,27 @@ statically =
6969
\fun = isDigit :: Char -> Bool\n"
7070
p_ "You have to pass the right type of values to functions, or the compiler\
7171
\ 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.")
7993

8094
concurrent :: Html ()
8195
concurrent =

0 commit comments

Comments
 (0)