codesnippets:typeapplications
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| codesnippets:typeapplications [2021/04/23 19:12] – created f2b216 | codesnippets:typeapplications [2025/10/08 00:48] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== {-# LANGUAGE TypeApplications #-} ====== | ====== {-# LANGUAGE TypeApplications #-} ====== | ||
| + | * allows to specify types to apply | ||
| + | * example, without type application | ||
| + | * code:< | ||
| + | module Main where | ||
| + | |||
| + | main :: IO () | ||
| + | main = print (read " | ||
| + | * compiles with error:< | ||
| + | app\Main.hs: | ||
| + | * Ambiguous type variable `a0' arising from a use of `read' | ||
| + | prevents the constraint `(Read a0)' from being solved. | ||
| + | Probable fix: use a type annotation to specify what `a0' should be. | ||
| + | These potential instances exist: | ||
| + | instance Read Ordering -- Defined in `GHC.Read' | ||
| + | instance Read Integer -- Defined in `GHC.Read' | ||
| + | instance Read a => Read (Maybe a) -- Defined in `GHC.Read' | ||
| + | ...plus 22 others | ||
| + | ...plus 12 instances involving out-of-scope types | ||
| + | (use -fprint-potential-instances to see them all) | ||
| + | * In the first argument of `print', | ||
| + | In the expression: print (read " | ||
| + | In an equation for `main': | ||
| + | | | ||
| + | 4 | main = print (read " | ||
| + | | | ||
| + | </ | ||
| + | * example, without type application | ||
| + | * code:< | ||
| + | module Main where | ||
| + | |||
| + | main :: IO () | ||
| + | main = print ((read " | ||
| + | </ | ||
| + | * example, with type application | ||
| + | * code:< | ||
| + | {-# LANGUAGE TypeApplications | ||
| + | |||
| + | module Main where | ||
| + | |||
| + | main :: IO () | ||
| + | main = print (read @Integer " | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== ✎ ===== | ||
| + | ~~DISCUSSION~~ | ||
codesnippets/typeapplications.1619197949.txt.gz · Last modified: (external edit)
