Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

binding a partially applied function in Haskell

I'm a Haskell newbie, so please excuse me if you find this question trivial:

How would I get GHCi to accept a declaration of this sort: let foo = fmap (*3) . fmap (+10)?

I tried adding a type declaration to foo (let foo :: [Int] -> [Int] = etc) to make the functor type explicit but the compiler responds Illegal Signature.

Thanks!

EDIT - Apparently there are quite a few ways to do this. I picked Tikhon's answer because his was among the first, and also fairly intuitive. Thanks, everyone!

like image 636
planarian Avatar asked Nov 30 '25 05:11

planarian


1 Answers

To give type signatures in ghci, the best way, not requiring any extensions, is to separate the signature and the binding with a semicolon,

let foo :: Num n => [n] -> [n]; foo = map (*3) . map (+ 10)
like image 121
Daniel Fischer Avatar answered Dec 02 '25 22:12

Daniel Fischer