小编and*_*wja的帖子

类型类默认方法实例化中的歧义类型解析

为什么以下代码无法键入?

{-# LANGUAGE AllowAmbiguousTypes, MultiParamTypeClasses #-}

module Main where

class Interface a b c where
  get :: a -> [b]
  change :: b -> c

  changeAll :: a -> [c]
  changeAll = map change . get

main = return ()
Run Code Online (Sandbox Code Playgroud)

如果我注释掉 的默认实例化--changeAll = map change . get,一切似乎都很好。但是,在实例化到位后,我收到此错误:

GHCi, version 8.6.5: http://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling Main             ( test.hs, interpreted )

test.hs:10:19: error:
    • Could not deduce (Interface a0 b0 c)
        arising from a use of …
Run Code Online (Sandbox Code Playgroud)

haskell types type-inference typeclass

3
推荐指数
1
解决办法
75
查看次数

标签 统计

haskell ×1

type-inference ×1

typeclass ×1

types ×1