简体   繁体   中英

Haskell Top Level Functions

I have a Haskell file open on the left side of my screen and ghci on the other half. I want to add functions to the file, save, and experiment with them in ghci. The problem is that I'm not totally sure how to declare top level functions. I'm not even sure I know what top level functions are. I figure they are just functions at the highest level of scope. So my question is what is the minimalist way to do this? For example...

let f1 x = x

What boilerplate code do I need to surround this with to make it compile so I can load it in ghci?

You don't need more boilerplate, but less! Just don't put the let in - that's used for GHCI, not for .hs files. It's also nice to add type annotations in source files, even though those are usually omitted in GHCI.

f1 :: a -> a
f1 x = x

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM