Tutorial by Examples

The type of the literal Prelude> :t 1 1 :: Num a => a choosing a concrete type with annotations You can specify the type as long as the target type is Num with an annotation: Prelude> 1 :: Int 1 it :: Int Prelude> 1 :: Double 1.0 it :: Double Prelude> 1 :: Word 1 it :: ...
The type of the literal Prelude> :t 1.0 1.0 :: Fractional a => a Choosing a concrete type with annotations You can specify the type with a type annotation. The only requirement is that the type must have a Fractional instance. Prelude> 1.0 :: Double 1.0 it :: Double Prelude> 1....
The type of the literal Without any extensions, the type of a string literal – i.e., something between double quotes – is just a string, aka list of characters: Prelude> :t "foo" "foo" :: [Char] However, when the OverloadedStrings extension is enabled, string literals be...
GHC's OverloadedLists extension allows you to construct list-like data structures with the list literal syntax. This allows you to Data.Map like this: > :set -XOverloadedLists > import qualified Data.Map as M > M.lookup "foo" [("foo", 1), ("bar", 2)] Just ...

Page 1 of 1