Send Beginners mailing list submissions to
[email protected]
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
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: Implementing instance of '^' operator (Harald Hanche-Olsen)
2. infinite type (Julian Rohrhuber)
3. Re: infinite type (Joel Neely)
4. Re: infinite type (Imants Cekusins)
5. Re: infinite type (Julian Rohrhuber)
6. Re: infinite type (Imants Cekusins)
----------------------------------------------------------------------
Message: 1
Date: Sun, 3 Jan 2016 13:06:55 +0000
From: Harald Hanche-Olsen <[email protected]>
To: "The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell" <[email protected]>
Subject: Re: [Haskell-beginners] Implementing instance of '^' operator
Message-ID: <etPan.56891cf4.7713523d.1095@fiinbeck>
Content-Type: text/plain; charset="utf-8"
-----Original Message-----
From:[email protected] <[email protected]>
Date:?3 January 2016 at 07:55:53
> As a ?hello world? example for type definitions, I like to define a numeric
> type that can
> handle the mod p multiplicative group, where p is prime. This requires:
> ? Implementing interface functions
[?]
I can?t help with the question you?re asking, but I have a minor nitpick: You
want to have
negate (Modp p 0) = Modp p 0,
and not Modp p p as in your current implementation.
? Harald
------------------------------
Message: 2
Date: Sun, 03 Jan 2016 14:31:13 +0100
From: Julian Rohrhuber <[email protected]>
To: "[email protected]" <[email protected]>
Subject: [Haskell-beginners] infinite type
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
The function g, when called with a binary function returns a type error which
I?d really like to understand: why is this type ?infinite" rather than just
incomplete or something similar? I would have expected some kind of partial
binding. Can someone help me with an explanation?
Prelude> let f g = g . g
Prelude> let sum x y = x + y
Prelude> f sum
<interactive>:14:3:
Occurs check: cannot construct the infinite type: a ~ a -> a
Expected type: (a -> a) -> a -> a
Actual type: a -> a -> a
Relevant bindings include
it :: (a -> a) -> a -> a (bound at <interactive>:14:1)
In the first argument of ?f?, namely ?sum?
In the expression: f sum
With a similar call using lambda expressions, the error is different:
Prelude> (\x y -> x + y) . (\x y -> x + y)
<interactive>:32:1:
Non type-variable argument in the constraint: Num (a -> a)
(Use FlexibleContexts to permit this)
When checking that ?it? has the inferred type
it :: forall a. (Num a, Num (a -> a)) => a -> (a -> a) -> a -> a
Prelude>
------------------------------
Message: 3
Date: Sun, 3 Jan 2016 07:42:14 -0600
From: Joel Neely <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] infinite type
Message-ID:
<caeezxahrymc0csvj7hgx-ukotk1p96bxgaehktslv8k1a0p...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
I'm curious as to the intended meaning of
let f g = g . g
Without reading further down, I immediately thought: "composing g onto g
must require that the argument and result types (domain and range) of g
must be identical".
Then, when I read
f sum
I don't know what that means, given that sum is [1] "a function of two
arguments" yielding a single value (or, if I want to have my daily dose of
curry, sum is [2] "a function of one argument yielding a (function of one
argument yielding a single value)".
With either reading, I don't know how to reconcile sum with the expectation
on the argument to f.
I think that's what the compiler is saying as well.
Expected type: (a -> a) -> a -> a
Actual type: a -> a -> a
The "expected type" expression seems to match what I expected from the
definition of f, and the "actual type" expression seems to match reading
[2].
So I'm wondering how that aligns with what you intended to express.
-jn-
On Sun, Jan 3, 2016 at 7:31 AM, Julian Rohrhuber <
[email protected]> wrote:
> The function g, when called with a binary function returns a type error
> which I?d really like to understand: why is this type ?infinite" rather
> than just incomplete or something similar? I would have expected some kind
> of partial binding. Can someone help me with an explanation?
>
> Prelude> let f g = g . g
> Prelude> let sum x y = x + y
> Prelude> f sum
>
> <interactive>:14:3:
> Occurs check: cannot construct the infinite type: a ~ a -> a
> Expected type: (a -> a) -> a -> a
> Actual type: a -> a -> a
> Relevant bindings include
> it :: (a -> a) -> a -> a (bound at <interactive>:14:1)
> In the first argument of ?f?, namely ?sum?
> In the expression: f sum
>
>
> With a similar call using lambda expressions, the error is different:
>
> Prelude> (\x y -> x + y) . (\x y -> x + y)
>
> <interactive>:32:1:
> Non type-variable argument in the constraint: Num (a -> a)
> (Use FlexibleContexts to permit this)
> When checking that ?it? has the inferred type
> it :: forall a. (Num a, Num (a -> a)) => a -> (a -> a) -> a -> a
> Prelude>
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
--
Beauty of style and harmony and grace and good rhythm depend on simplicity.
- Plato
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20160103/8c140243/attachment-0001.html>
------------------------------
Message: 4
Date: Sun, 3 Jan 2016 16:03:48 +0100
From: Imants Cekusins <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] infinite type
Message-ID:
<cap1qinzhpoob-yfhgghwv2sfatqdzpmymzsrn8pndz+9+wj...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hello Julian,
Prelude> let f g = g . g
Prelude> let sum x y = x + y
Prelude> f sum
If you are trying to call 'f' and see the result, args are missing.
If you are trying to create new type, use 'let'.
Prelude> (\x y -> x + y) . (\x y -> x + y)
Similar story. Let or args
;)
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20160103/404ebf2e/attachment-0001.html>
------------------------------
Message: 5
Date: Sun, 03 Jan 2016 20:46:19 +0100
From: Julian Rohrhuber <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] infinite type
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
Hi all, than you for your helpful replies.
>
> On 03.01.2016, at 16:03, Imants Cekusins <[email protected]> wrote:
>
> Hello Julian,
>
> Prelude> let f g = g . g
> Prelude> let sum x y = x + y
> Prelude> f sum
>
> If you are trying to call 'f' and see the result, args are missing.
>
> If you are trying to create new type, use 'let'.
>
> Prelude> (\x y -> x + y) . (\x y -> x + y)
>
> Similar story. Let or args
Hello Imants ? same with ?let? here:
Prelude> let f g = g . g
Prelude> let sum x y = x + y
Prelude> let sum' = f sum
<interactive>:43:14:
Occurs check: cannot construct the infinite type: a ~ a -> a
> On 03.01.2016, at 14:42, Joel Neely <[email protected]> wrote:
> I'm curious as to the intended meaning of
>
> let f g = g . g
>
> Without reading further down, I immediately thought: "composing g onto g must
> require that the argument and result types (domain and range) of g must be
> identical?.
yes, that domain and range are the same is implied when you rise a function "to
a power? (which is what f does). I just assumed that arity and type are two
different things in Haskell.
> Then, when I read
>
> f sum
>
> I don't know what that means, given that sum is [1] "a function of two
> arguments" yielding a single value (or, if I want to have my daily dose of
> curry, sum is [2] "a function of one argument yielding a (function of one
> argument yielding a single value)".
>
> With either reading, I don't know how to reconcile sum with the expectation
> on the argument to f.
As you wondered what I was trying to express, I was thinking along reading [2].
With:
Prelude> let z = sum 2
Prelude> let z' = f z
z' is a function with one argument, and yes, this works because z was one with
a single argument.
But assuming that function composition (.) is a function too, I was curious
what would happen if I applied it partially.
So an intermediate step would have been this:
let k = (\x y -> x + y) . (\x -> x + 1)
which is fine. It leaves a binary op function as I expected.
By contrast,
let k = (\x y -> x + y) . (\x y -> x + y)
returns Non type-variable argument in the constraint: Num (a -> a)
Instead of something like following which I had dared to expect:
let k = (\z -> (\x y -> x + y + z))
What really made me wonder then was how come that
f sum
would return not a "Non type-variable argument?, but "cannot construct the
infinite type: a ~ a -> a?
Where does the infinity come from?
------------------------------
Message: 6
Date: Sun, 3 Jan 2016 21:01:41 +0100
From: Imants Cekusins <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] infinite type
Message-ID:
<CAP1qinb7=j_2c5zfmtybes_jo80gxep58xdcp1yfnh3v+wh...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Prelude> let f g = g . g
Prelude> let sum x y = x + y
Prelude> let sum' = f sum
Occurs check: cannot construct the infinite type: a ~ a -> a
If f and sum were defined in a module, given a signature, I suppose this
would compile.
Similarly, sometimes valid functions defined within function body without
signatures sometimes make compiler complain. Once such functions are moved
to top (module) level and given a signature, compiler is happy.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20160103/a738613e/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 91, Issue 4
****************************************