Created
April 14, 2014 22:35
-
-
Save alco/10687583 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
defmodule M do | |
@type mytype :: String.t | |
end | |
defmodule N do | |
@spec hi(M.mytype) :: M.mytype | |
def hi(x), do: x | |
end | |
defmodule Mac do | |
defmacro mkfun(name, arg, type) do | |
quote do | |
@spec unquote(name)(unquote(type)) :: unquote(type) | |
def unquote(name)(unquote(arg)), do: unquote(arg) | |
end | |
end | |
end | |
defmodule Foo do | |
require Mac | |
Mac.mkfun(:hello, x, M.mytype) | |
end | |
IO.puts Foo.hello "abc" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment