Changes between Initial Version and Version 2 of Ticket #1749


Ignore:
Timestamp:
Sep 29, 2007 8:57:03 PM (7 years ago)
Author:
sorear
Comment:

Thanks for the report, but I think I can explain this.

Firstly, and quite unrelatedly, you can use triple braces to request monospace, see my edit to the description.

'sf' has no arguments, so the monomorphism restriction applies. The body of 'sf' is assigned a typing derivation of the form:

Monad m1, Monad m2, f :: b -> c |- return $ \b -> return (f b) : m1 (a -> m2 b)

Because 'm1' and 'm2' are constrained by type classes, the monomorphism restriction forces them to be assigned to fully non-polymorphic types; unfortunately this means that it is insufficiently polymorphic for SF.

Possible workarounds include:

{-# LANGUAGE NoMonomorphismRestriction #-}
-- for older GHC, {-# OPTIONS_GHC -fno-monomorphism-restriction #-}

or:

sfPure :: (b -> c) -> SF b c
sfPure f = SF sf where
     returnST :: a -> ST s a
     returnST = return

     sf = returnST $ \b -> returnST (f b)  -- no type classes, no MR

or the aforementioned explicit annotation approach (explicit annotations disable the MR).

Unfortunately, the monomorphism restriction is specified by the Haskell 98 Language Report, so you're more likely to get results from the Haskell-prime committee than you are from specific implementors.

Stefan

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #1749 – Description

    initial v2  
     1{{{ 
    12> type SFST s a b = a -> ST s b 
    23> newtype SF a b = SF { runSF :: forall s. ST s (SFST s a b) } 
     4}}} 
    35 
    46When making this into an instance of Arrow, compose works beautifully: 
    57 
     8{{{ 
    69> sfCompose :: SF b c -> SF c d -> SF b d 
    710> sfCompose bc cd = SF sf where 
     
    1013>     runCd <- runSF cd 
    1114>     return $ \b -> runBc b >>= runCd 
     15}}} 
    1216 
    1317but pure gives an odd message: 
    1418 
     19{{{ 
    1520> sfPure :: (b -> c) -> SF b c 
    1621> sfPure f = SF sf where 
    1722>     sf = return $ \b -> return (f b) 
     23}}} 
    1824 
     25{{{ 
    1926frp_typebug.lhs:20:12: 
    2027    Inferred type is less polymorphic than expected 
     
    2734                 where 
    2835                     sf = return $ (\ b -> return (f b)) 
     36}}} 
    2937 
    3038This can be worked around using scoped type variables: 
     39 
     40{{{ 
    3141> sfPure2 :: (b -> c) -> SF b c 
    3242> sfPure2 (f :: b -> c) = SF sf where 
    3343>     sf :: forall s. ST s (SFST s b c)  
    3444>        = return $ \b -> return (f b) 
     45}}} 
    3546 
    3647but it's ugly.