====== Type defaulting ====== Stil not clear how this works: * module Main where main :: IO () main = do print $ negate 4 Output: * -4 ...or this: * module Main where main :: IO () main = do print $ sin 3 Output: * 0.1411200080598672 Despite, lentgthy discussions here: [[https://www.reddit.com/r/haskell/comments/1r3w3w/implicit_type_conversion_for_value_constants/]] And despite this: [[https://www.haskell.org/onlinereport/decls.html#sect4.3.4]] And despite this: [[https://kseo.github.io/posts/2017-01-04-type-defaulting-in-haskell.html]] ...which states: "Haskell default rule can be summarized as:" * default Num Integer default Real Integer default Enum Integer default Integral Integer default Fractional Double default RealFrac Double default Floating Double default RealFloat Double Latest reserach in GHC.Num shows: * module GHC.Num (module GHC.Num, module GHC.Integer, module GHC.Natural) where #include "MachDeps.h" import GHC.Base import GHC.Integer import GHC.Natural infixl 7 * infixl 6 +, - default () -- Double isn't available yet, -- and we shouldn't be using defaults anyway Even more puzzling, this here does not compile: * module Main where default () main :: IO () main = do print $ sin 3 Compiler error: * app\Main.hs:7:5: error: * Ambiguous type variable `a0' arising from a use of `print' prevents the constraint `(Show a0)' from being solved. Probable fix: use a type annotation to specify what `a0' should be. These potential instances exist: instance Show Ordering -- Defined in `GHC.Show' instance Show Integer -- Defined in `GHC.Show' instance Show a => Show (Maybe a) -- Defined in `GHC.Show' ...plus 22 others ...plus 28 instances involving out-of-scope types (use -fprint-potential-instances to see them all) * In a stmt of a 'do' block: print $ sin 3 In the expression: do print $ sin 3 In an equation for `main': main = do print $ sin 3 | 7 | print $ sin 3 | ^^^^^^^^^^^^^ It will work again, like this: * module Main where default (Float) main :: IO () main = do print $ sin 3 Output: * 0.14112 ===== ✎ ===== ~~DISCUSSION~~