Skip to content

Commit

Permalink
Clarify how to use types for more than validation
Browse files Browse the repository at this point in the history
The "Statically typed" paragraph mentions that type are "not only a form
of guarantee", but the examples did not reflect that.
  • Loading branch information
gelisam committed Feb 15, 2015
1 parent 2348fa3 commit 08b77c4
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/HL/View/Home/Features.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,27 @@ statically =
\fun = isDigit :: Char -> Bool\n"
p_ "You have to pass the right type of values to functions, or the compiler\
\ will reject the program:"
rejectedHaskellPre "Type error" "isDigit 1"
p_ "You can decode bytes into text:"
haskellPre "bytes = Crypto.Hash.SHA1.hash \"hello\" :: ByteString\n\
\text = decodeUtf8 bytes :: Text\n"
p_ "But you cannot decode Text, which is already a vector \
\of Unicode points:"
rejectedHaskellPre "Type error" "doubleDecode = decodeUtf8 (decodeUtf8 bytes)"
haskellPre "fun char -- typechecks"
rejectedHaskellPre "Type error" "fun int"
p_ (do "Notice how the types "
code_ "Char"
" and "
code_ "Char -> Bool"
" tell you that you can combine those values by applying "
code_ "fun"
" to "
code_ "char"
". With more sophisticated types, and with a bit of experience, it's \
\often possible to use a Haskell library without reading any tutorial, \
\just by examining the types of the values it exports.")
p_ "A precise type is also a useful guide when implementing a function."
haskellPre "mySnd :: (a, b) -> b\n\
\mySnd (x, y) = _hole"
p_ (do "Here, the compiler will tell you that you need a value of type "
code_ "b"
" to fill the hole, and that among the values which are in scope, "
code_ "y"
" is the only one which has the required type.")

concurrent :: Html ()
concurrent =
Expand Down

0 comments on commit 08b77c4

Please sign in to comment.