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

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

问题描述

我看到并使用 :: 符号无处不在,但仍然不知道在Haskell中编程时 :: 符号的含义,例如

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
--  ??

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

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

推荐答案

您可以在Google上搜索 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.

在Haskell中,没有它,您的程序通常可以正常运行(尽管您将希望使用它来完善所定义的任何函数的规范,这是一种很好的做法).

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).

这个想法是,您可以在任何地方(甚至在表达式的中间)插入 :: ... 来表示通过Compiler先生的方式,该表达式应为 ... ".如果可以证明情况并非如此,则编译器将引发错误.

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.

我认为您也可以使用它来将功能投射"到所需的版本;例如如果一个函数是多态的"(具有通用的类型签名),而您实际上想要一个 Integer ,那么您可以对结果值进行 :: Integer ;不过我有点生锈.

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.

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

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