[GHC] #963: monadic Num instance not found in ghci

GHC trac at galois.com
Tue Oct 24 22:46:49 EDT 2006


#963: monadic Num instance not found in ghci
---------------------------------+------------------------------------------
    Reporter:  rwxr-xr-x at gmx.de  |       Owner:       
        Type:  bug               |      Status:  new  
    Priority:  normal            |   Milestone:       
   Component:  GHCi              |     Version:  6.6  
    Severity:  normal            |    Keywords:       
  Difficulty:  Unknown           |    Testcase:       
Architecture:  x86               |          Os:  Linux
---------------------------------+------------------------------------------
Here's my code (fun.hs):
 {{{
 {-# OPTIONS_GHC -fglasgow-exts -fallow-undecidable-instances #-}

 import Control.Monad.Reader

 instance Eq (a -> b) where
     _ == _ = error "whoops"

 instance Show (a -> b) where
     show = const "<fun>"

 instance (Num a, Monad m, Eq (m a), Show (m a)) => Num (m a) where
     fromInteger = return . fromInteger
     abs = liftM abs
     signum = liftM signum
     (+) = liftM2 (+)
     (*) = liftM2 (*)
     (-) = liftM2 (-)

 instance (Fractional a, Monad m, Num (m a)) => Fractional (m a) where
     fromRational = return . fromRational
     (/) = liftM2 (/)

 instance (Floating a, Monad m, Fractional (m a)) => Floating (m a) where
     pi = return pi
     exp = liftM exp
     log = liftM log
     sin = liftM sin
     cos = liftM cos
     tan = liftM tan
     sinh = liftM sinh
     cosh = liftM cosh
     tanh = liftM tanh
     asin = liftM sin
     acos = liftM cos
     atan = liftM tan
     asinh = liftM sinh
     acosh = liftM cosh
     atanh = liftM tanh

 }}}

 Test session:
 {{{
 $ ghci fun.hs
    ___         ___ _
   / _ \ /\  /\/ __(_)
  / /_\// /_/ / /  | |      GHC Interactive, version 6.6, for Haskell 98.
 / /_\\/ __  / /___| |      http://www.haskell.org/ghc/
 \____/\/ /_/\____/|_|      Type :? for help.

 Loading package base ... linking ... done.
 [1 of 1] Compiling Main             ( fun.hs, interpreted )
 Ok, modules loaded: Main.
 *Main> 1 2

 <interactive>:1:0:
     No instance for (Num (t1 -> t))
       arising from the literal `1' at <interactive>:1:0-2
     Possible fix: add an instance declaration for (Num (t1 -> t))
     In the expression: 1 2
     In the definition of `it': it = 1 2
 }}}

 Expected result:
 {{{
 Loading package mtl-1.0 ... linking ... done.
 1
 }}}

 This used to work in ghci-6.4. What's also weird is that manually lifting
 one number seems to help:
 {{{
 *Main> (1 + 2) undefined

 <interactive>:1:1:
     No instance for (Num (a -> t))
       arising from the literal `1' at <interactive>:1:1
     Possible fix: add an instance declaration for (Num (a -> t))
     In the first argument of `(+)', namely `1'
     In the expression: (1 + 2) undefined
     In the definition of `it': it = (1 + 2) undefined
 *Main> (1 + const 2) undefined
 3
 }}}

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/963>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the Glasgow-haskell-bugs mailing list