Ticket #303 (closed bug: duplicate)

Opened 7 years ago

Last modified 3 years ago

Rebindable syntax doesn't work as advertised

Reported by: nobody Owned by: nobody
Priority: normal Milestone:
Component: Compiler (Type checker) Version: 6.8.3
Keywords: Cc: ryani.spam@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: rebindable/T303 Blocked By:
Blocking: Related Tickets:

Description (last modified by simonpj) (diff)

--
-- According to section 7.3.5. Rebindable syntax in the
user's manual
-- this should work (unless I totally misunderstood it).
-- It doesn't.
--
-- Compile with -fno-implicit-prelude
--
--     Lennart
--

import Prelude hiding(Monad(..))

class B a where
    b :: a

instance B Bool where
    b = False

class M m where 
    return :: a -> m a
    (>>=)  :: (B a) => m a -> (a -> m b) -> m b
    (>>)   :: (B a) =>  m a -> m b -> m b
    fail   :: String -> m a
  
    p >> q  = p >>= \ _ -> q
    fail s  = error s
   
instance M Maybe where
    return x = Just x
    (>>=) = error "bind"

test :: Maybe Bool
test = do
    x <- return True
    return (x && x)

unJust (Just x) = x

main = print (unJust test)

Change History

Changed 7 years ago by nobody

Logged In: NO 

The documentation was wrong - it now says that >>= etc have
to be polymorphic.

Changed 7 years ago by nobody

Logged In: NO 

I would much prefer if the implementation had changed to
match the documentation. :)

  -- Lennart

Changed 7 years ago by nobody

Logged In: NO 

You're not alone:

http://www.haskell.org/pipermail/haskell/2005-January/015113.html

Changed 7 years ago by simonpj

Logged In: YES 
user_id=50165

This is a bug, and I plan to fix it.  

To date I only knew of a couple of people who cared (Amr 
Sabry, Arthur van Leeuwen, perhpas Ashley Yakely).  This 
makes one more.  Can you say a bit more about why it'd be 
useful to you. To help motivate me...

This won't be in 6.4, but I will do it, esp if more people yell.

Changed 7 years ago by nobody

Logged In: NO 

My motivation is identical to Amr's.  I was trying out his
quantum computation stuff, and then you need an additional
constraint on the bind operation in the monad.  So I tried
using my own monad definition, but it failed.

It's not really a big deal, but if it's reasonably easy to
fix...

Changed 7 years ago by simonpj

  • status changed from assigned to closed
Logged In: YES 
user_id=50165

Fixed for do-notation

Changed 3 years ago by ryani

  • status changed from closed to reopened
  • resolution Fixed deleted
  • version changed from 6.4 to 6.8.3
  • os set to Unknown
  • architecture set to Unknown

This seems to be broken in 6.8.3, at least for "weird" monad types. Test case follows:

{-# LANGUAGE NoImplicitPrelude #-}
module T where
import qualified Prelude as P

class IxMonad m where
    return :: a -> m i i a
    (>>=) :: m i j a -> (a -> m j k b) -> m i k b
    (>>)  :: m i j a -> m j k b -> m i k b
    m >> n = m >>= \_ -> n
    
    fail :: P.String -> m i j a
    fail s = P.error s

data T a b c = T
instance IxMonad T where
    return _ = T
    m >>= f  = T
    fail _   = T

testM :: T (a,b) b a
testM = T

test1 = testM >>= \x -> return x

test2  = do
   x <- testM
   return x

test1 compiles fine, but test2 (which should be identical up-to-sugaring) fails.

$ ghc -c -XNoImplicitPrelude T.hs
T.hs:27:3:
    Occurs check: cannot construct the infinite type: b = (a, b)
      Expected type: T (a, b) b t
      Inferred type: T (a, b) (a, b) a
    In the expression: return x
    In the expression:
        do x <- testM
           return x

Changed 3 years ago by ryani

  • cc ryani.spam@… added

Changed 3 years ago by simonpj

  • status changed from reopened to closed
  • difficulty set to Unknown
  • testcase set to rebindable/T303
  • resolution set to duplicate
  • description modified (diff)

This is really a dup of #1537, which was fixed last year but never got into 6.8. Works in HEAD (and hence the upcoming GHC 6.10). However, I've added your program as a new test case in the regression test suite rebindable/T303, so that we'll know if it ever fails in the future.

Simon

Changed 3 years ago by simonmar

  • architecture changed from Unknown to Unknown/Multiple

Changed 3 years ago by simonmar

  • os changed from Unknown to Unknown/Multiple
Note: See TracTickets for help on using tickets.