나는 Elixir에서 프로토콜을 정의한 다음 두 개의 모듈에서 구현하려고합니다. 내 문제는 그래서, 그 모듈은 단지 에이전트 래퍼이다 :Elixir에서 에이전트를 사용하여 프로토콜 구현
다음의 결과defprotocol Proto do
def foo(proto)
end
defmodule A do
def start_link() do
Agent.start_link(fn -> :a end)
end
end
defimpl Proto, for: A do
def foo(proto) do
Agent.get(proto, fn a -> a end)
end
end
defmodule B do
def start_link() do
Agent.start_link(fn -> :b end)
end
end
defimpl Proto, for: B do
def foo(proto) do
Agent.get(proto, fn b -> b end)
end
end
{:ok, a_pid} = A.start_link()
value = Proto.foo(a_pid)
,
** (Protocol.UndefinedError) protocol Proto not implemented for #PID<0.88.0>
test.exs:1: Proto.impl_for!/1
test.exs:2: Proto.foo/1
(elixir) lib/code.ex:363: Code.require_file/2
직접이 문제를 해결할 수있는 방법이 있나요?
Perfect! 고맙습니다. 저는 엘릭서의 세계에 익숙하지 않아 언어의 철학을 익히는 데 약간의 시간이 걸릴 수 있습니다. –