해당 기능 종속성에 의해 표현되는 제한 조건은 컬렉션 유형 c
이 주어진 경우 해당 항목 유형이 i
인 것으로 결정됩니다. 예를 들어, c ~ [a]
, 즉 컬렉션이 a
의 목록 인 경우 i ~ a
을 확인할 수 있어야합니다.
기능 의존성이 없으면 우리는 두 개의 인스턴스를 가질 수 있습니다. Unfoldable [a] a
(명백한/예정된 인스턴스) 및 Unfoldable [a] [a]
(insert = concat
, singleton = id
과 같은 것).
{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-}
class Unfoldable c i where
empty :: c
instance Unfoldable [a] a where
empty = []
instance Unfoldable [a] [a] where
empty = []
xs :: [a]
xs = empty
을이 결과 :
No instance for (Unfoldable [a] i0) arising from a use of `empty'
The type variable `i0' is ambiguous
Relevant bindings include
xs :: [a]
Note: there are several potential instances:
instance Unfoldable [a] a
instance Unfoldable [a] [a]
In the expression: empty
In an equation for `xs': xs = empty
typechecker 다음
empty :: [a]
같은 것을 볼 경우, 인스턴스가 사용하는 선택의 방법이 없습니다