Algae v0.12.2 Algae View Source

Link to this section Summary

Link to this section Types

Link to this type ast() View Source
ast() :: {atom, any, any}

Link to this section Functions

Link to this function call_type(new_module, module_ctx) View Source
call_type(module, [module]) :: ast

Construct a data type AST

Link to this function data_ast(modules, type) View Source
data_ast(module | [module], ast) :: ast
Link to this function data_ast(name, default, type_ctx) View Source
data_ast([module], any, ast) :: ast
Link to this function default_type(struct_type) View Source

—- Id —

defmodule Id do defdata do: id :: any() end

—- Sum —-

defmodule Either do defsum do

defdata Left  :: any()
defdata Right :: any()

end end

defmodule Either do defdata do: Left :: any() | Right :: any() end

—- Product —

defmodule Rectangle do data do: width :: number(), height :: number() end

— Both —

data Stree a = Tip | Node (Stree a) a (Stree a) defmodule Stree do defdata do

Tip :: any() | Node :: (left :: t()), (middle = 42 :: any()), (right :: t())

end end

defmodule Stree do defsum do

defdata Tip :: any()

defproduct Node do
  left :: Stree.t()
  middle = 42 :: any()
  right :: Stree.t()
end

end end

Link to this macro defdata(module_ctx, list) View Source (macro)
Link to this macro defsum(list) View Source (macro)
defsum(term, [{:do, {:__block__, [any], ast}}]) :: ast

Generate the AST for a sum type definition

Link to this function extract_name(module_chain) View Source
extract_name({any, any, atom} | [module]) :: [module]
Link to this function extract_part_name(arg) View Source
extract_part_name({:defdata, any, [{:::, any, [any]}]}) :: [module]
Link to this function modules(top, module_ctx) View Source
modules(module, [module]) :: [module]
Link to this function or_types(list, module_ctx) View Source
or_types([ast], module) :: [ast]