[Haskell-cafe] explicit type for "local" functions
Tom Ellis
tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk
Wed Jan 27 11:12:26 UTC 2021
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))
More information about the Haskell-Cafe
mailing list