Skip to content

Instantly share code, notes, and snippets.

@alco
Created April 14, 2014 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alco/10687583 to your computer and use it in GitHub Desktop.
Save alco/10687583 to your computer and use it in GitHub Desktop.
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