To call generated code from Elchemy you don't need anything special.
Each function exposed from a module can be called either in it's regular or curried form.
Keep in mind that in case of functions expecting a higher-order function[s] in its parameters Elchemy will also do it's magic to make sure it's compatible both ways.
For instance if your function looks like that:
applyFunction2 : (a -> b -> c) -> a -> b -> c applyFunction2 f p1 p2 = f p1 p2
You can call it Elixir way:
apply_function2(fn a, b -> a + b end)
As well as Elchemy (curried) way:
apply_function2(fn a -> fn b -> a + b end end)
And it will work as fine
To call elixir from Elchemy you need to define a foreign function interface.
To do that you can use
ffi special syntax (?)
ffi requires the function to have a very specific format, which is:
- You need to make sure the type signature is adequate to the corresponding typespec of a function
- There should be no explicitly stated parameters (Defined as
f = ...not
f a b c = ...)
- The only expression inside the function should be an ffi call in a format of:
ffi "Module" "function"
A good example of an ffi call would be
upcase : String -> String upcase = ffi "String" "upcase"
A generated code of that statement would be
@spec upcase(String.t) :: String.t curry upcase/1 verify as: String.upcase/1 def upcase(a1), do: String.upcase(a1)
verify, as: is a type safety generator about which you can read more in testing section.