gpt4 book ai didi

haskell : Use -XFlexibleContexts to permit this?

转载 作者:行者123 更新时间:2023-12-03 18:08:54 25 4
gpt4 key购买 nike

我的代码如下:

calcstep ::Integral a => a -> a
calcstep n = calcstep2 n 0

calcstep2 :: Integral (Integral a, Integral b) => a -> b -> a
calcstep2 1 k = k
calcstep2 n k | odd n = calcstep2 (n/2) (k+1)
| otherwise = calcstep2 (n*3+1) (k+1)

错误如下:

Non type-variable argument

in the constraint: Integral (Integral a, Integral b)

(Use -XFlexibleContexts to permit this)

In the type signature for `calcstep2': calcstep2 :: Integral (Integral a, Integral b) => a -> b -> a

Failed, modules loaded: none.



这是什么意思?我该如何解决?

最佳答案

ghci您可以设置FlexibleContexts像这样:

:set -XFlexibleContexts

在源文件的开头,您应该使用:
{-# LANGUAGE FlexibleContexts #-}

在 GHC 手册中,您可以找到有关 using language extensions 的更多信息。 .

无论如何,我认为克里斯的回答更接近你真正想要的。

关于 haskell : Use -XFlexibleContexts to permit this?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21375556/

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