Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Got "Non type-variable argument in the   constraint" error for
      a simple function (wizard)
   2. Re:  Got "Non type-variable argument in the constraint" error
      for a simple function (Frerich Raabe)
   3. Re:  Got "Non type-variable argument in the constraint" error
      for a simple function (David McBride)
   4. Re:  Got "Non type-variable argument in the constraint" error
      for a simple function (wizard)


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

Message: 1
Date: Tue, 9 Feb 2016 00:24:47 +0800
From: wizard <xie.zh...@gmail.com>
To: beginners@haskell.org
Subject: [Haskell-beginners] Got "Non type-variable argument in the
        constraint" error for a simple function
Message-ID:
        <CA+RmsoXdh-cF6SyLQWUqJjB1Dv=jyfp1wn-nayolwfcchsq...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Dear all,

I just started to learn Haskell with learnyouahaskell.com and at the very
beginning, I met a strange issue with following simple function:

-- why does work with "toZero 10" but not for "toZero -10"?toZero ::
(Integral t) => t -> [t]toZero 0 = [0]toZero x = if x > 0 then x :
toZero (x - 1)
                    else x : toZero (x + 1)


This function works as expected for positive arguments, e.g., "toZero 10"
gives me [10,9,8,7,6,5,4,3,2,1,0]. However, GHCI will raise following error
if I give it a negative argument, e.g., "toZero -10":

*Main> toZero -10

<interactive>:12:1:
    Non type-variable argument in the constraint: Num (t -> [t])
    (Use FlexibleContexts to permit this)
    When checking that ?it? has the inferred type
      it :: forall t. (Integral t, Num (t -> [t])) => t -> [t]


This seems strange to me as 10 and -10 has exactly the same type "Num a =>
a". I've done with chapter 1~10 of learnyouahaskell.com but still has no
idea on why this error. Anybody can help to explain this?
Thanks a lot.

Regards
Zhiyi Xie
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160209/5f6c76d2/attachment-0001.html>

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

Message: 2
Date: Mon, 08 Feb 2016 17:32:36 +0100
From: Frerich Raabe <ra...@froglogic.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Got "Non type-variable argument in
        the constraint" error for a simple function
Message-ID: <7ecc86c4487ee1d4ef7a4e1b78fa4...@roundcube.froglogic.com>
Content-Type: text/plain; charset=US-ASCII; format=flowed

On 2016-02-08 17:24, wizard wrote:
> Dear all,
> 
> I just started to learn Haskell with learnyouahaskell.com and at the very
> beginning, I met a strange issue with following simple function:
> 
> -- why does work with "toZero 10" but not for "toZero -10"?
> toZero :: (Integral t) => t -> [t]

[..]

> This function works as expected for positive arguments, e.g., "toZero 10"
> gives me [10,9,8,7,6,5,4,3,2,1,0]. However, GHCI will raise following error
> if I give it a negative argument, e.g., "toZero -10":

[..]

The issue is that  'toZero -10' is parsed as 'toZero minus 10', i.e. it's not 
a negative value you're passing there. It expects 'toZero' to be a numeric 
value.

Try toZero (-10) instead.

-- 
Frerich Raabe - ra...@froglogic.com
www.froglogic.com - Multi-Platform GUI Testing


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

Message: 3
Date: Mon, 8 Feb 2016 11:43:29 -0500
From: David McBride <toa...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Got "Non type-variable argument in
        the constraint" error for a simple function
Message-ID:
        <can+tr43s3e36w3n-cesqflkckb2r3f4sslwdunat9vxjnwr...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

If you are wondering why you are having this problem it is because - can be
interpretted as either a one argument negation or a two argument
subtraction.  If you put parenthesis around (-n) where n is an integer, it
will interpret it as unary, something that will not happen in other
operators.

>:t (-)
(-) :: Num a => a -> a -> a
>:t (+)
(+) :: Num a => a -> a -> a
>:t (-1)
(-1) :: Num a => a
>:t (+1)
(+1) :: Num a => a -> a
>:t (1-1)
(1-1) :: Num a => a
>:t (1+1)
(1+1) :: Num a => a


On Mon, Feb 8, 2016 at 11:24 AM, wizard <xie.zh...@gmail.com> wrote:

> Dear all,
>
> I just started to learn Haskell with learnyouahaskell.com and at the very
> beginning, I met a strange issue with following simple function:
>
> -- why does work with "toZero 10" but not for "toZero -10"?toZero :: 
> (Integral t) => t -> [t]toZero 0 = [0]toZero x = if x > 0 then x : toZero (x 
> - 1)
>                     else x : toZero (x + 1)
>
>
> This function works as expected for positive arguments, e.g., "toZero 10"
> gives me [10,9,8,7,6,5,4,3,2,1,0]. However, GHCI will raise following error
> if I give it a negative argument, e.g., "toZero -10":
>
> *Main> toZero -10
>
> <interactive>:12:1:
>     Non type-variable argument in the constraint: Num (t -> [t])
>     (Use FlexibleContexts to permit this)
>     When checking that ?it? has the inferred type
>       it :: forall t. (Integral t, Num (t -> [t])) => t -> [t]
>
>
> This seems strange to me as 10 and -10 has exactly the same type "Num a =>
> a". I've done with chapter 1~10 of learnyouahaskell.com but still has no
> idea on why this error. Anybody can help to explain this?
> Thanks a lot.
>
> Regards
> Zhiyi Xie
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160208/fedf46a6/attachment-0001.html>

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

Message: 4
Date: Tue, 9 Feb 2016 04:20:48 +0800
From: wizard <xie.zh...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Got "Non type-variable argument in
        the constraint" error for a simple function
Message-ID:
        <ca+rmsoujwmp1qcg7nulcczjd5jjnk9wewlmntcn3s+5jd_a...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Thanks Frerich and David! I got it, :-)

2016-02-09 0:43 GMT+08:00 David McBride <toa...@gmail.com>:

> If you are wondering why you are having this problem it is because - can
> be interpretted as either a one argument negation or a two argument
> subtraction.  If you put parenthesis around (-n) where n is an integer, it
> will interpret it as unary, something that will not happen in other
> operators.
>
> >:t (-)
> (-) :: Num a => a -> a -> a
> >:t (+)
> (+) :: Num a => a -> a -> a
> >:t (-1)
> (-1) :: Num a => a
> >:t (+1)
> (+1) :: Num a => a -> a
> >:t (1-1)
> (1-1) :: Num a => a
> >:t (1+1)
> (1+1) :: Num a => a
>
>
> On Mon, Feb 8, 2016 at 11:24 AM, wizard <xie.zh...@gmail.com> wrote:
>
>> Dear all,
>>
>> I just started to learn Haskell with learnyouahaskell.com and at the
>> very beginning, I met a strange issue with following simple function:
>>
>> -- why does work with "toZero 10" but not for "toZero -10"?toZero :: 
>> (Integral t) => t -> [t]toZero 0 = [0]toZero x = if x > 0 then x : toZero (x 
>> - 1)
>>                     else x : toZero (x + 1)
>>
>>
>> This function works as expected for positive arguments, e.g., "toZero 10"
>> gives me [10,9,8,7,6,5,4,3,2,1,0]. However, GHCI will raise following error
>> if I give it a negative argument, e.g., "toZero -10":
>>
>> *Main> toZero -10
>>
>> <interactive>:12:1:
>>     Non type-variable argument in the constraint: Num (t -> [t])
>>     (Use FlexibleContexts to permit this)
>>     When checking that ?it? has the inferred type
>>       it :: forall t. (Integral t, Num (t -> [t])) => t -> [t]
>>
>>
>> This seems strange to me as 10 and -10 has exactly the same type "Num a
>> => a". I've done with chapter 1~10 of learnyouahaskell.com but still has
>> no idea on why this error. Anybody can help to explain this?
>> Thanks a lot.
>>
>> Regards
>> Zhiyi Xie
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>>
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160209/800d6646/attachment.html>

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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 92, Issue 11
*****************************************

Reply via email to