codesnippets:typeapplications

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
codesnippets:typeapplications [2021/04/23 19:12] – created f2b216codesnippets: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:<code Haskell>
 +module Main where
 +
 +main :: IO ()
 +main = print (read "123")</code>
 +    * compiles with error:<code>
 +app\Main.hs:4:15: error:
 +    * 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', namely `(read "123")'
 +      In the expression: print (read "123")
 +      In an equation for `main': main = print (read "123")
 +  |
 +4 | main = print (read "123")
 +  |               ^^^^^^^^^^
 +</code>
 +  * example, without type application
 +    * code:<code Haskell>
 +module Main where
 +
 +main :: IO ()
 +main = print ((read "123") :: Integer)
 +</code>
 +  * example, with type application
 +    * code:<code Haskell>
 +{-# LANGUAGE TypeApplications  #-}
 +
 +module Main where
 +
 +main :: IO ()
 +main = print (read @Integer "123")
 +</code>
 +
 +
 +===== ✎ =====
 +~~DISCUSSION~~
codesnippets/typeapplications.1619197949.txt.gz · Last modified: (external edit)

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki