3
私はGHC 8.2.1を使用しています。私は、次のモジュールがあります。このHasFieldインスタンスが解決されないのはなぜですか?
{-# 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
そして、この他の1:
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
インスタンスが解決されないのはなぜですか?