User Tools

Site Tools


codesnippets:typeapplications

{-# LANGUAGE TypeApplications #-}

  • allows to specify types to apply
  • example, without type application
    • code:
      module Main where
       
      main :: IO ()
      main = print (read "123")
    • compiles with error:
      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")
        |               ^^^^^^^^^^
  • example, without type application
  • example, with type application
    • code:
      {-# LANGUAGE TypeApplications  #-}
       
      module Main where
       
      main :: IO ()
      main = print (read @Integer "123")

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
You could leave a comment if you were logged in.
codesnippets/typeapplications.txt · Last modified: by 127.0.0.1

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