[Haskell-beginners] infinite type

Joel Neely joel.neely at gmail.com
Sun Jan 3 13:42:14 UTC 2016


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 <
julian.rohrhuber at musikundmedien.net> 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
> Beginners at haskell.org
> 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.html>


More information about the Beginners mailing list