How to specify types for Haskell set builder notation?

In particular, I want to do something like this:

myfunc:: [(Integer, Integer)]
myfunc = [(x^2 - y^2, 2 * x * y) | x <- [1..], y <- [1.. (x-1)]]

When I try to load this through ghci, I get

    Warning: Defaulting the following constraint(s) to type `Integer'
         `Integral t' arising from a use of `^' at myfunc.hs:76:20-22

So, I know that x should obviously be Integer, how do I go further and let Haskell know what I want?

+3
source share
2 answers

, ^ (Num a, Integral b) => a -> b -> a, ^ . Integer, Haskell , a Integer, b. , , Integer . , .

, , , , Integer, :

(x^(2::Integer) - y^(2::Integer), 2 * x * y)

: [] , .

+11

, 2, x ( y).

KennyTM (xx - yy,...) .

, - , , , ( "-Wall" ), , , . , ; , . , , , .

+2

Source: https://habr.com/ru/post/1753855/


All Articles