Skip to content

Instantly share code, notes, and snippets.

@christhekeele
Created August 16, 2021 20:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christhekeele/7e1f3d73d51e5fb871e51e438df95c47 to your computer and use it in GitHub Desktop.
Save christhekeele/7e1f3d73d51e5fb871e51e438df95c47 to your computer and use it in GitHub Desktop.
Example compile-time dependency adapter and assertions
defmodule Ash.SAT.Solver.Behaviour do
@callback function(:input) :: :return
end
cond do
{:module, Picosat} = Code.ensure_loaded(Picosat) ->
defmodule Ash.SAT.Solver do
@behaviour Ash.SAT.Solver.Behaviour
def function(:input), do: :picsat_specific
end
{:module, Csp} = Code.ensure_loaded(Csp) ->
IO.warn(
"using in-effecient Csp fallback,
helpful instructions here"
)
defmodule Ash.SAT.Solver do
@behaviour Ash.SAT.Solver.Behaviour
def function(:input), do: :csp_specific
end
{:error, :nofile} ->
raise CompileError,
"no SAT solver dependency installed,
helpful instructions here"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment