wfcing
This commit is contained in:
@@ -7,16 +7,8 @@
|
||||
]).
|
||||
|
||||
-export([
|
||||
|
||||
zero/0, one/0,
|
||||
add/1, add/2,
|
||||
mul/1, mul/2
|
||||
]).
|
||||
|
||||
|
||||
-type sentence() :: wfc_sentence:sentence().
|
||||
|
||||
|
||||
%% constructors
|
||||
-spec
|
||||
zero()
|
||||
|
||||
+21
-3
@@ -26,7 +26,7 @@
|
||||
%% constructors
|
||||
%%--------------------------
|
||||
|
||||
-spec zero() :: sentence().
|
||||
-spec zero() -> sentence().
|
||||
|
||||
zero() ->
|
||||
{s, []}.
|
||||
@@ -60,16 +60,34 @@ to_list({s, Words}) -> {ok, Words};
|
||||
to_list(Bad) -> {error, wfc_utils:str("wfc_sentence:to_list: bad sentence: ~tp", [Bad])}.
|
||||
|
||||
|
||||
|
||||
-spec validate(sentence()) -> ok | {error, string()}.
|
||||
|
||||
validate({s, [W | Rest]}) ->
|
||||
case wfc_word:validate(W) of
|
||||
ok -> validate({s, Rest});
|
||||
Error -> Error
|
||||
end;
|
||||
validate({s, []}) ->
|
||||
ok;
|
||||
validate(Bad) ->
|
||||
{error, wfc_utils:str("wfc_sentence:validate: bad sentence: ~tp", [Bad])}.
|
||||
|
||||
|
||||
%%---------------------------
|
||||
%% prim ops
|
||||
%%---------------------------
|
||||
|
||||
add({s, X}, {s, Y}) -> {s, disjoint_union(X, Y)}.
|
||||
-spec add(sentence(), sentence()) -> sentence().
|
||||
|
||||
disjoint_union(X, Y) ->
|
||||
add({s, X}, {s, Y}) -> {s, symdiff(X, Y)}.
|
||||
|
||||
symdiff(X, Y) ->
|
||||
ordsets:subtract(ordsets:union(X, Y),
|
||||
ordsets:intersection(X, Y)).
|
||||
|
||||
|
||||
-spec add([sentence()]) -> sentence().
|
||||
|
||||
add([S | Rest]) -> add(S, add(Rest));
|
||||
add([]) -> zero().
|
||||
|
||||
@@ -108,6 +108,3 @@ mul({w, X}, {w, Y}) ->
|
||||
|
||||
mul([Word | Rest]) -> mul(Word, mul(Rest));
|
||||
mul([]) -> one().
|
||||
|
||||
|
||||
add(
|
||||
|
||||
Reference in New Issue
Block a user