Created
December 17, 2017 18:20
-
-
Save dylan-chong/17f92595fd9510abf56f405da8847421 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defprotocol P do | |
def x(p) | |
end | |
defimpl P, for: Integer do | |
def x(p) do | |
p + 1 | |
end | |
end | |
defimpl P, for: M do | |
end | |
defimpl P, for: Any do | |
def x(p) do | |
p | |
end | |
end | |
defmodule M do | |
@derive [P] | |
defstruct [:a] | |
end | |
P.x 2 # => 3 | |
P.x "a" # => Error Not implemetned for string | |
P.x %M{} # => %M{} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment