在Haskell中,::(双冒号)代表什么? [英] What does :: (double colon) stand for in Haskell?

查看:330
本文介绍了在Haskell中,::(双冒号)代表什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到并使用 :: 符号到处,但仍然不知道 :: code> symbol表示在Haskell中编程时,例如

  run :: Int  - > Int  - >诠释
- ??

:: (双冒号)在Haskell中代表?

解决方案

您可以google for haskelldouble colon或类似的东西;在这种情况下,您可以命名它。



在Haskell中,如果没有它,程序通常会运行正常(尽管您会希望使用它来磨练你定义的任何函数的规范,这是一个好习惯)。

这个想法是你可以插入一个: :... 在任何地方(甚至在表达式中间)说:按照Compiler先生的方式,这个表达式应该是类型 ... 。如果可以证明,情况可能并非如此,那么编译器会抛出一个错误。



我认为你也可以用它来将函数投射到你的版本想;例如如果一个函数是多态的(有一个普通的类型签名)并且你真的想要一个 Integer ,那么你可以做 :: Integer 可能是由此产生的值;虽然我有点生疏。


I see and use the :: symbols everywhere but still don't know what the :: symbol means when programming in Haskell, e.g.

run :: Int -> Int -> Int
--  ??

What does :: (double colon) stand for in Haskell?

解决方案

You can google for haskell "double colon" or similar things; it's unfortunately a bit hard to google for syntax, but in this case you can name it.

In Haskell, your programs will often run fine without it (though you will want to use it to hone the specification of any functions you define, and it is good practice).

The idea is that you can insert a :: ... anywhere (even in the middle of an expression) to say "by the way Mr. Compiler, this expression should be of type ...". The compiler will then throw an error if it can be proved this may not be the case.

I think you can also use it to "cast" functions to the versions you want; e.g. if a function is "polymorphic" (has a general type signature) and you actually want, say an Integer, then you could do :: Integer on the resulting value perhaps; I'm a bit rusty though.

这篇关于在Haskell中,::(双冒号)代表什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆