Ich verwende GHC 8.2.1. Ich habe folgendes Modul:Warum wird diese HasField-Instanz nicht aufgelöst?
{-# 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
Und diese andere:
module Foo (Foo(..)) where
data Foo a = Foo { getDims :: (Int, Int), getData :: [a] }
Mein Problem ist, dass, wenn ich beide Module importiert und ich versuche, so etwas wie zu tun:
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE DataKinds #-}
import Moat
import Foo
import GHC.Records
oops :: (Int,Int)
oops = getField @"getDims" (moat (Foo (5,5) ['c']))
Ich erhalte diesen Fehler:
Warum wird die HasField
Instanz nicht aufgelöst?