@@ -87,6 +87,11 @@ defmodule Module.Types.Descr do
8787 @ boolset :sets . from_list ( [ true , false ] , version: 2 )
8888 def boolean ( ) , do: % { atom: { :union , @ boolset } }
8989
90+ ## Function constructors
91+
92+ @ doc """
93+ The top function type.
94+ """
9095 def fun ( ) , do: % { fun: @ fun_top }
9196
9297 @ doc """
@@ -118,6 +123,15 @@ defmodule Module.Types.Descr do
118123 fun ( List . duplicate ( none ( ) , arity ) , term ( ) )
119124 end
120125
126+ @ doc """
127+ Creates a function from non-overlapping function clauses.
128+ """
129+ def fun_from_non_overlapping_clauses ( [ { args , return } | clauses ] ) do
130+ Enum . reduce ( clauses , fun ( args , return ) , fn { args , return } , acc ->
131+ intersection ( acc , fun ( args , return ) )
132+ end )
133+ end
134+
121135 @ doc """
122136 Tuples represent function domains, using unions to combine parameters.
123137
@@ -1087,20 +1101,20 @@ defmodule Module.Types.Descr do
10871101 end
10881102 end
10891103
1090- # Transforms a binary decision diagram (BDD) into the canonical form { domain, arrows, arity} :
1104+ # Transforms a binary decision diagram (BDD) into the canonical ` domain- arrows` pair :
10911105 #
10921106 # 1. **domain**: The union of all domains from positive functions in the BDD
10931107 # 2. **arrows**: List of lists, where each inner list contains an intersection of function arrows
1094- # 3. **arity**: Function arity (number of parameters)
10951108 #
1096- ## Return Values
1109+ # # # Return Values
10971110 #
1098- # - `{domain, arrows, arity}` for valid function BDDs
1111+ # - `{:ok, domain, arrows}` for valid function BDDs
1112+ # - `{:badarity, supported_arities}` if the given arity is not supported
10991113 # - `:badfun` if the BDD represents an empty function type
11001114 #
11011115 # ## Internal Use
11021116 #
1103- # This function is used internally by `fun_apply `, and others to
1117+ # This function is used internally by `fun_apply_* `, and others to
11041118 # ensure consistent handling of function types in all operations.
11051119 defp fun_normalize ( % { fun: bdd } , arity , mode ) do
11061120 { domain , arrows , bad_arities } =
@@ -1216,9 +1230,9 @@ defmodule Module.Types.Descr do
12161230 # Takes all the paths from the root to the leaves finishing with a 1,
12171231 # and compile into tuples of positive and negative nodes. Positive nodes are
12181232 # those followed by a left path, negative nodes are those followed by a right path.
1219- def fun_get ( bdd ) , do: fun_get ( [ ] , [ ] , [ ] , bdd )
1233+ defp fun_get ( bdd ) , do: fun_get ( [ ] , [ ] , [ ] , bdd )
12201234
1221- def fun_get ( acc , pos , neg , bdd ) do
1235+ defp fun_get ( acc , pos , neg , bdd ) do
12221236 case bdd do
12231237 :fun_bottom -> acc
12241238 :fun_top -> [ { pos , neg } | acc ]
0 commit comments