GHCi能告诉我一个本地Haskell函数的类型吗?

编程入门 行业动态 更新时间:2024-10-26 16:35:40
本文介绍了GHCi能告诉我一个本地Haskell函数的类型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否有可能查询ghci是否为其他函数内的函数推断的类型?

这是一个快速和丑陋的黑客攻击,但我通常做的只是以错误的方式使用该函数,并阅读错误消息:

inc x = x + 1 其中f(y,z)= y + z g = f :: Char

GHCi输出:

无法匹配预期的类型'Char'与推断类型`(t,t) - > t'在表达式中:f :: Char

尽管这样会遗漏掉上下文 Num t => ,这通常会为我提供足够的信息以继续。

Is it possible to query the ghci for the type it inferred for a function inside another function?

解决方案

This is a quick and ugly hack, but what I usually do is just use the function in the wrong way and read the error message:

inc x = x + 1 where f (y, z) = y + z g = f :: Char

GHCi output:

Couldn't match expected type `Char' against inferred type `(t, t) -> t' In the expression: f :: Char

Although this leaves out the context Num t =>, this usually does provide me with enough information to continue.

更多推荐

GHCi能告诉我一个本地Haskell函数的类型吗?

本文发布于:2023-07-26 11:43:59,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:能告诉我   函数   类型   GHCi   Haskell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!