up-to-date-real-world-haskell icon indicating copy to clipboard operation
up-to-date-real-world-haskell copied to clipboard

Content missing in webpage preview

Open ftxi opened this issue 5 years ago • 0 comments
trafficstars

Hi, I was reading Chapter 6: Using Type Classes. I found several lines missing (for the declaration of UniqueId was unclear):

screenshot

However, as I looked into the source, these lines are still there:


#+BEGIN_NOTE
The type and newtype keywords

Although their names are similar, the ~type~ and ~newtype~
keywords have different purposes. The ~type~ keyword gives us
another way of referring to a type, like a nickname for a friend.
Both we and the compiler know that ~[Char]~ and ~String~ names
refer to the same type.

In contrast, the ~newtype~ keyword exists to /hide/ the nature of
a type. Consider a ~UniqueID~ type.

#+CAPTION: Newtype.hs
#+BEGIN_SRC haskell
newtype UniqueID = UniqueID Int
    deriving (Eq)
#+END_SRC

The compiler treats ~UniqueID~ as a different type from ~Int~. As
a user of a ~UniqueID~, we know only that we have a unique
identifier; we cannot see that it is implemented as an ~Int~.
#+END_NOTE

Perhaps this is a problem, but I am not sure at which level it arises.

ftxi avatar Sep 05 '20 03:09 ftxi