0
다음과 같은 선언을 모나드 컴파일러로 선언하려면 어떻게해야합니까?모나드 클래스를 올바르게 정의하기
module Main where
instance Monad m where
-- "return" constructs a one-item list.
return x = [x]
-- "bind" concatenates the lists obtained by applying f to each item in list xs.
xs >>= f = concat (map f xs)
-- The zero object is an empty list.
mzero = []
현재 나는 다음과 같은 오류가 발생합니다 :
monad_ex1.hs:9:3: ‘mzero’ is not a (visible) method of class ‘Monad’
내 코드 https://en.wikipedia.org/wiki/Monad_(functional_programming)#Collections에서, 목표는, 그에서 컴파일 가능한 코드를 생성 실행 ghci에서 그것을 가져 와서 놀러입니다. 코드에서
제거 mzero 다른 비밀 메시지로 연결 :
Illegal instance declaration for ‘Monad m’
(All instance types must be of the form (T a1 ... an)
where a1 ... an are *distinct type variables*,
and each type variable appears at most once in the instance head.
Use FlexibleInstances if you want to disable this.)
In the instance declaration for ‘Monad m’
오류가 말하듯이 모나드에는 "제로 객체"또는 "mzero"가 없습니다. – melpomene
'인스턴스 모나드 m '은 모든 가능한 유형을'm '이'모나드 '의 인스턴스로 만듭니다. '인스턴스 Monad []'가 필요 하겠지만 이미 표준 라이브러리에 존재합니다. 이와 같은 인스턴스를 제공하려면 자신의 클래스 또는 자신의 유형을 정의해야합니다. – melpomene
모나드 타입 클래스에 대한 인스턴스를 정의하는 동안 왜 'mzero'를 추가했는지 명확하지 않습니다. – BarbedWire