Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Contradictory Behaviour of Lambda Functions

Using the following definitions:

lenDigits n = length (show n) factorial n = product [1..n] 

I evaluate the following

Prelude> ((lenDigits . factorial) 199) <= 199 False Prelude> (\i -> ((lenDigits . factorial) i) <= i) 199 True 

What is the reason for such behaviour? As I see it, the first expression is just the same as the second expression with the lambdas reduced.

like image 209
Agnishom Chattopadhyay Avatar asked Dec 08 '16 16:12

Agnishom Chattopadhyay


1 Answers

Because in the first expression the first 199 has type Integer and the second has Int. But in the second expression both have type Int and factorial 199 can't be represented by the type Int.

like image 103
freestyle Avatar answered Oct 12 '22 13:10

freestyle