explicit type for "local" functions

Just a short and probably simple question. 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)) It is easy to set explicitly the type of "collatz" by writing before the function definition: collatz :: Integer->Int But can I set explicitly the type of the "local" function "coll" ? Thanks

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))
participants (2)
-
Jean-Marc Alliot
-
Tom Ellis