Using Int-type versus integral constraint. Advantage?

Consider these (more or less) equivalent types of signatures:

f1 :: [a] -> Int -> a
f2 :: Integral b => [a] -> b -> a

f2 is more general than f1, and this is a big advantage, but is there any advantage of f1 over f2?

It seems that in solutions to the H-99 problems and in many published solutions to various Project Euler problems, the form f1 appears much more often than f2.

I'm not sure why. Is it just a programmer who is too lazy, or is there a cost of execution when switching to a more general version (f2), or is there another reason?

+3
source share
1 answer
  • - , length , Int. generic *, genericLength, , .

  • Int . Integral a , Integral.

  • Int , . , ByteString Int (, , ), , Int, 29+ .

  • , . , , , , .

+8

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


All Articles