
27 Jan
2021
27 Jan
'21
6:12 a.m.
On Wed, Jan 27, 2021 at 11:48:10AM +0100, Jean-Marc Alliot wrote:
Let's consider the following function: collatz n = let coll (n,cpt) | n==1 = (1,cpt) | even n = coll (div n 2,cpt+1) | odd n = coll (div (n*3+1) 2,cpt+1) in snd (coll (n,0)) [..] But can I set explicitly the type of the "local" function "coll" ?
Do you mean this? collatz :: Integer -> Int collatz n = let coll :: (Integer, Int) -> (Integer, Int) coll (n,cpt) | n==1 = (1,cpt) | even n = coll (div n 2,cpt+1) | odd n = coll (div (n*3+1) 2,cpt+1) in snd (coll (n,0))