多态类型的显式类型签名 [英] Explicit type signatures for polymorphic types
问题描述
我在回顾 Haskell:函数式编程的工艺,但是第356页的类型签名已经引发了我循环。
这里有一个简单的例子:
succeed :: b - >解析ab
成功val inp = [(val,inp)]
b - >如果
成功,解析b
> Int - >诠释
成功a = a
和
成功Int - > Int - >诠释
成功ab = a + b
您必须参与的参数数量类型声明权利?如果您的类型声明只有一个类型变量,那么如何取 val
和 imp
> 成功:: b - >解析ab
应该读取,取一个 a
类型的变量并返回一个类型的解析ab
,不接受两个变量...其中 inp
允许?
- >
类似的扩展类型。例如: type Foo = Int - > Int
succeed :: Int - > Foo
成功a b = a + b
I'm reviewing Haskell: The Craft of Functional Programming, however the type signatures on page 356 have thrown me for a loop.
Here is a simple one:
succeed :: b -> Parse a b
succeed val inp = [( val, inp )]
How can that be b -> Parse a b
, if
succeed Int -> Int
succeed a = a
and,
succeed Int -> Int -> Int
succeed a b = a + b
The amount of arguments your taking has to be in the type declaration right? How can you take val
, and imp
, if your type declaration only has one type variable: succeed :: b -> Parse a b
is supposed to read, take one variable of type a
and return a type of Parse a b
, not take two variables... where is inp
permitted?
Because Parse
is a type synonym with ->
in its expansion. Example:
type Foo = Int -> Int
succeed :: Int -> Foo
succeed a b = a + b
这篇关于多态类型的显式类型签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!