[ ghc-Feature Requests-1124080 ] Implicit Parameters and monomorphism

SourceForge.net noreply at sourceforge.net
Tue Mar 8 05:35:44 EST 2005


Feature Requests item #1124080, was opened at 2005-02-16 17:01
Message generated for change (Comment added) made by simonmar
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=358032&aid=1124080&group_id=8032

Category: None
Group: None
Status: Open
>Priority: 3
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
>Summary: Implicit Parameters and monomorphism

Initial Comment:
http://www.haskell.org/pipermail/haskell-cafe/2005-January/008571.html

Notes some oddness with recursive binding of implicit
parameters. Roughly, giving a type signature to a
function with implicit params causes its bindings to
act recursively, despite what section 7.4.5.2 of the
user's guide says.

----------------------------------------------------------------------

>Comment By: Simon Marlow (simonmar)
Date: 2005-03-08 10:35

Message:
Logged In: YES 
user_id=48280

This "bug" is just to record the strange interaction between
implicit parameters and monomorphism.

[adding text of original message]

Jim Apple wrote:

 > Does anyone have examples of these? This one scares the
foo out of me:
 >
 >>> * It's not even safe in general to add a signature
giving the same type
 >>> that the compiler would infer anyway

Here's an example:

    > len :: [a] -> Int
    >
    > len xs = let ?accum = 0 in len' xs
    >
    > len' [] = ?accum
    > len' (x:xs) = let ?accum = ?accum + (1::Int) in len' xs

    *Main> :t len'
    len' :: forall a. (?accum :: Int) => [a] -> Int
    *Main> len "hello"
    0

    > len :: [a] -> Int
    >
    > len xs = let ?accum = 0 in len' xs
    >
    > len' :: forall a. (?accum :: Int) => [a] -> Int
    >
    > len' [] = ?accum
    > len' (x:xs) = let ?accum = ?accum + (1::Int) in len' xs

    *Main> :t len'
    len' :: forall a. (?accum :: Int) => [a] -> Int
    *Main> len "hello"
    5

This happens as a side effect of the way that type inference
currently 
works on recursive binding groups. It happens with typeclass 
dictionaries too, but it isn't observable because they can't
be rebound 
in a local scope.

-- Ben

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=358032&aid=1124080&group_id=8032


More information about the Glasgow-haskell-users mailing list