[英]Haskell type signature
I'm having trouble understanding this type signature: 我无法理解这种类型的签名:
config :: Config Snap ()
config = setPort 8888 defaultConfig
Where are the ->
stating the params and return type of the function? ->
在哪里说明函数的参数和返回类型? What am I missing here? 我在这里错过了什么?
The ->
infix type constructor takes an argument type on the left and a result type on the right. ->
缀类型构造函数在左侧采用参数类型,在右侧采用结果类型。 config
has no parameters, and it makes no sense to write ->
with nothing on the left, so the result type is the only type. config
没有参数,它是没有意义的写->
什么也没有在左边,所以结果类型是唯一的类型。
You can do the same thing with types you're more familiar with. 您可以使用您更熟悉的类型执行相同的操作。 For example: 例如:
example1 :: Int
example1 = 1
example2 :: Maybe Integer
example2 = Just 2
example3 :: [Double]
example3 = [1,2,3]
example4 :: Either String Int
example4 = Right 4
It's not really a function here - it's a value (well it's the configuration for snap): a Snap Config
with the Snap
monad and empty ()
additional ( other
) information sitting on it. 它实际上不是一个函数 - 它是一个值(它是快照的配置):一个Snap Config
其中包含Snap
monad和empty ()
附加( other
)信息。
As you can read in the documentation it's more or less a starting point and you use the functions here to set additional informations. 正如您可以在文档中看到的那样,它或多或少是一个起点,您可以使用此处的函数来设置其他信息。
So in a sense it's just the same as writing 所以在某种意义上它与写作一样
myInt :: Int
myInt = 4
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.