gpt4 book ai didi

haskell - 逐步推导类型

转载 作者:行者123 更新时间:2023-12-03 14:39:15 25 4
gpt4 key购买 nike

我在派生类型方面遇到了真正的问题,并且根本不了解如何派生类型。

我定义了一个函数 f具有以下实现:

f x y z = x * y * z

函数的类型签名 f是:
f :: Num c => c -> c -> c -> c

很简单,对吧?

现在,申请 fmapid函数并查看类型签名。

首先,让我们申请 map f :
a -> b "The signature of the first argument of map
~ ~
c -> c -> c -> c "The signature of the f function

你可以在上面看到,我是如何分离并获得类型相等的,即 a ~ cb ~ c -> c -> c .

然后,让我们申请 id f
a -> a           "The signature of the id
~ ~
c -> c -> c -> c "The signature of the f function

就像我上面分开的那样,我会说 a ~ ca ~ c -> c -> c ,但这是错误的,我不明白为什么。我完全按照上面的示例原理进行操作。正确的应该是 a ~ c -> c -> c -> c .

有人可以逐步向我解释它,派生类型是如何工作的吗?我会说,我完全理解派生类型的概念。

最佳答案

你实际上是在问题中自己写的:

  • a -> b -- The signature of the first argument of map
  • a -> a -- The signature of id

  • 要比较苹果和苹果,你需要从
  • a -> b -- The signature of the first argument of map
  • a -- The signature of the first argument of id
  • 关于haskell - 逐步推导类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45549153/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com