2
일부 라이브러리의 다중 매개 변수 타입 클래스를 타입 동의어로 대체하려고합니다. 타입 생성자로 작업 할 때까지 모든 것이 잘되었습니다. 이 코드의 마지막 두 줄은 컴파일되지 않습니다.타입 패밀리와 타입 생성자
{-# LANGUAGE TypeFamilies, FlexibleContexts #-}
import qualified Data.Map as M
-- | A regular arrangement of tiles.
class Eq (Index g) => Grid g where
type Index g
-- | Returns the indices of all tiles in a grid.
indices :: g -> [Index g]
-- plus other functions
-- | A map from tile positions in a grid to values.
data LGridMap g v = LGridMap { toGrid :: g, toMap :: M.Map (Index g) v }
instance Grid g => Grid (LGridMap g v) where
type Index (LGridMap g v) = Index g
indices = indices . toGrid
class GridMap gm where
type BaseGrid gm
type Value gm
instance GridMap (LGridMap g v) where
BaseGrid gm = g -- line 26
Value = v -- line 27
내가 얻는 컴파일 오류는 다음과 같습니다
../Amy.hs:26:3:
Pattern bindings (except simple variables) not allowed in instance declarations
BaseGrid gm = g
../Amy.hs:27:3:
Pattern bindings (except simple variables) not allowed in instance declarations
Value = v
Failed, modules loaded: none.
LGridMap
을 정의 할 수있는 더 나은 방법이 있나요? LGridMap
이 GridMap
의 인스턴스임을 지정하는 방법이 있습니까?