qqq type:
qqq :: Show a => Maybe a -> IO ()
This means that qqq takes one parameter of type Maybe a and returns an IO action without a value, while the restriction a implements the Show class. To find out what Show , you can use :i Show in ghci.
Show is a type that requires that the type value can be converted to a string. qqq has a limitation because print wants to print the value ( print is of type Show a => a -> IO () ). Maybe is not a type, but a data type. You can learn more about typeclasses here .
You can let the GHC output the type signature by typing the function in the .hs file, then loading the file with ghci ( ghci Myfile.hs ), and then type :t qqq to display the type. You can also define a function in an interactive session with let qqq n = case n of { Nothing -> print "abc"; Just x -> print "def" >> print x } let qqq n = case n of { Nothing -> print "abc"; Just x -> print "def" >> print x } (this looks a bit different because the function definition should be on the same line in ghci, but the meaning is the same).
When the main qqq calls with qqq (Just 43) , it becomes clear that the concrete type Maybe a is numeric (ghci is Integer by default), so qqq has the concrete type Maybe Integer -> IO () . However, the main qqq calls with qqq Nothing , a can be any (this is ambiguous), and ghci reports an error.
source share