Gmail Calendar Documents Web Reader more »
Recently Visited Groups | Help | Sign in
Google Groups Home
typing trouble
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Dirk van Deun  
View profile  
 More options Nov 19 2007, 5:05 pm
Newsgroups: comp.lang.haskell
From: dvand...@vub.spam-me-not.ac.be (Dirk van Deun)
Date: 19 Nov 2007 22:05:40 GMT
Local: Mon, Nov 19 2007 5:05 pm
Subject: typing trouble
I have a very irritating typing problem.  A program contains a list of
methods (as the program is an interpreter for an object oriented
language), with the following type:

primitivesList :: (MonadIO m) => [(MethodName, (Arity, [Value] -> m Value))]

I want to extract the method names in a separate list, so I write:

primitivesNames :: [MethodName]
primitivesNames = map fst primitivesList

We apply ghc, and the result is:

tingle-0.7.2.hs:408:26:
    Ambiguous type variable `m' in the constraint:
      `MonadIO m'
        arising from a use of `primitivesList' at tingle-0.7.2.hs:408:26-39
    Probable fix: add a type signature that fixes these type variable(s)

Line 408 is the "primitivesNames = ..." line.

Is there a way to fix this just by adding typing information ?  I do not
see how or where...

Dirk van Deun
--
Ceterum censeo Redmond delendum


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tzy-Jye Daniel Lin  
View profile  
 More options Nov 19 2007, 7:17 pm
Newsgroups: comp.lang.haskell
From: Tzy-Jye Daniel Lin <dt...@andrew.cmu.edu>
Date: Tue, 20 Nov 2007 00:17:02 +0000 (UTC)
Local: Mon, Nov 19 2007 7:17 pm
Subject: Re: typing trouble
Disclaimer:
I am not an expert.  Sometimes I get lucky and make good educated guesses.

On Mon, 19 Nov 2007 22:05:40 +0000, Dirk van Deun wrote:
> primitivesList :: (MonadIO m) => [(MethodName, (Arity, [Value] -> m Value))]

This is not permissible as a top-level declaration without
-XNoMonomorphismRestriction / -fno-monomorphism-restriction.

When a CAF has polymorphic type, it may be evaluated multiple times,
once per type.

> primitivesNames :: [MethodName]
> primitivesNames = map fst primitivesList

The evaluation of primitivesList depends on the choice of (MonadIO m).
primitiveNames does not.  See the problem?

> Is there a way to fix this just by adding typing information ?  I do not
> see how or where...

a. Don't declare primitivesNames at the top-level.  It's simple and short,
   and can be declared within a context where the choice of m is fixed.
b. Pick some (MonadIO m), and write
    map fst (primitivesList :: [(... InstanceOfMonadIO ...)])

    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dirk van Deun  
View profile  
 More options Nov 20 2007, 8:38 am
Newsgroups: comp.lang.haskell
From: dvand...@vub.spam-me-not.ac.be (Dirk van Deun)
Date: 20 Nov 2007 13:38:11 GMT
Local: Tues, Nov 20 2007 8:38 am
Subject: Re: typing trouble
Tzy-Jye Daniel Lin (dt...@andrew.cmu.edu) wrote:

: > primitivesList :: (MonadIO m) => [(MethodName, (Arity, [Value] -> m Value))]

: This is not permissible as a top-level declaration without
: -XNoMonomorphismRestriction / -fno-monomorphism-restriction.

: When a CAF has polymorphic type, it may be evaluated multiple times,
: once per type.

: > primitivesNames :: [MethodName]
: > primitivesNames = map fst primitivesList

: The evaluation of primitivesList depends on the choice of (MonadIO m).
: primitiveNames does not.  See the problem?

Thank you.  That makes lots of sense.  I was looking for the problem in
the newly added code, but the code that had been functioning for
weeks was the real culprit.

It does indeed work if I change the type to:

primitivesList :: M.Map MethodName
                        (Arity, [Value] -> ErrorT String (StateT MyState IO) Value)

Dirk van Deun
--
Ceterum censeo Redmond delendum


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2010 Google