简体   繁体   English

Haskell顶级功能

[英]Haskell Top Level Functions

I have a Haskell file open on the left side of my screen and ghci on the other half. 我在屏幕的左侧打开了一个Haskell文件,另一半打开了ghci。 I want to add functions to the file, save, and experiment with them in ghci. 我想将功能添加到文件中,保存并在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? 我需要围绕什么样板代码进行编译,以便可以将其加载到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. 只是不要let -用于GHCI,而不是.hs文件。 It's also nice to add type annotations in source files, even though those are usually omitted in GHCI. 即使在GHCI中通常省略类型注释,也可以在源文件中添加类型注释。

f1 :: a -> a
f1 x = x

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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