#963 closed bug (fixed)
monadic Num instance not found in ghci
Reported by: | rwxr-xr-x@… | Owned by: | |
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | GHCi | Version: | 6.6 |
Keywords: | Cc: | ||
Operating System: | Linux | Architecture: | x86 |
Type of failure: | Test Case: | tc217 | |
Blocked By: | Blocking: | ||
Related Tickets: | Differential Revisions: |
Description
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
Change History (2)
comment:1 Changed 8 years ago by simonpj
- Resolution set to fixed
- Status changed from new to closed
- Test Case set to tc217
comment:2 Changed 14 months ago by simonpj <simonpj@…>
Note: See
TracTickets for help on using
tickets.
This bug is the same as #179.
I've finally fixed it. The patch should work fine on the 6.6 branch.
Simon