【发布时间】:2017-08-13 10:04:13
【问题描述】:
我正在使用 GHC 8.2.1。我有以下模块:
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Moat (Moat,moat) where
import GHC.Records (HasField(..))
newtype Moat r = Moat r
moat :: r -> Moat r
moat = Moat
instance HasField s r v => HasField s (Moat r) v where
getField (Moat r) = getField @s r
还有这个:
module Foo (Foo(..)) where
data Foo a = Foo { getDims :: (Int, Int), getData :: [a] }
我的问题是,当我导入了两个模块并尝试执行以下操作时:
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE DataKinds #-}
import Moat
import Foo
import GHC.Records
oops :: (Int,Int)
oops = getField @"getDims" (moat (Foo (5,5) ['c']))
我收到此错误:
No instance for (HasField "getDims" (Moat (Foo Char)) (Int, Int))
arising from a use of ‘getField’
为什么HasField 实例没有被解析?
【问题讨论】: