如何阅读haskell类型签名? [英] how to read haskell type signature?

查看:35
本文介绍了如何阅读haskell类型签名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我把这个声明放在了我的 ghci

So I put this statement on my ghci

jkl x f y = f (map (+y) x)

我把它放回去了.

jkl :: Num b => [b] -> ([b] -> t) -> b -> t

但是我读的时候很困惑.根据我的理解,jkl 是 num 类型,它接受 [b]、[b] 和 t,以及 b.最后它会输出t.这是正确的阅读方式吗?

But I'm confused when I read it. From my understanding jkl is type num that takes [b], [b] and t, and b. in the end it will output t. is that the right way to read it?

推荐答案

jkl :: Num b => [b] -> ([b] -> t) -> b -> t

调用 jkl 的人必须

  • 选择类型 bt
  • 保证 b 是在数字类型中选择的(Num b 约束)
  • 传递一个 [b](b 的列表)作为第一个参数
  • 传递一个函数[b] ->t 作为第二个参数(即采用 [b] 并返回一个 t)
  • 传递一个 b 作为第三个参数
  • 接收t作为最终结果
  • choose types b and t
  • guarantee that b was chosen among numeric types (the Num b constraint)
  • pass a [b] (list of b) as first argument
  • pass a function [b] -> t as second argument (i.e. taking [b] and returning a t)
  • pass a b as third argument
  • receive t back as a final result

这篇关于如何阅读haskell类型签名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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