Skip to content

Commit 02357e5

Browse files
committed
refactor to use new utils
1 parent 7617a6c commit 02357e5

File tree

2 files changed

+30
-31
lines changed

2 files changed

+30
-31
lines changed

src/frontend/Typechecker.ml

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -393,25 +393,9 @@ let check_fn ~is_cond_dist loc tenv id es =
393393
(Stan_math_signatures.is_stan_math_function_name
394394
(Utils.normalized_name id.name)) ->
395395
Semantic_error.returning_fn_expected_nonfn_found loc id.name |> error
396-
| [] -> (
397-
let gen_prefix l = String.concat ~sep:"_" (List.rev l) in
398-
match List.rev (String.split id.name ~on:'_') with
399-
| (("lpmf" | "lupmf") as suffix) :: tl
400-
when Utils.is_distribution_name
401-
(String.concat ~sep:"_" (List.rev tl @ ["lpdf"])) ->
402-
Semantic_error.returning_fn_expected_wrong_dist_suffix_found loc
403-
(gen_prefix tl, suffix)
404-
|> error
405-
| (("lpdf" | "lupdf") as suffix) :: tl
406-
when Utils.is_distribution_name
407-
(String.concat ~sep:"_" (List.rev tl @ ["lpmf"])) ->
408-
Semantic_error.returning_fn_expected_wrong_dist_suffix_found loc
409-
(gen_prefix tl, suffix)
410-
|> error
411-
| suffix :: tl
412-
when List.mem Utils.cumulative_distribution_suffices_w_rng suffix
413-
~equal:String.equal ->
414-
let prefix = gen_prefix tl in
396+
| [] ->
397+
( match Utils.split_distribution_suffix id.name with
398+
| Some (prefix, suffix) -> (
415399
let known_families =
416400
List.map
417401
~f:(fun (_, y, _, _) -> y)
@@ -420,18 +404,31 @@ let check_fn ~is_cond_dist loc tenv id es =
420404
let is_known_family s =
421405
List.mem known_families s ~equal:String.equal
422406
in
423-
if is_known_family prefix then
424-
Semantic_error.returning_fn_expected_undeclared_dist_suffix_found
425-
loc (prefix, suffix)
426-
|> error
427-
else
428-
Semantic_error.returning_fn_expected_undeclaredident_found loc
429-
id.name
430-
|> error
431-
| _ ->
407+
match suffix with
408+
| ("lpmf" | "lumpf")
409+
when Utils.is_distribution_name (prefix ^ "_lpdf") ->
410+
Semantic_error.returning_fn_expected_wrong_dist_suffix_found loc
411+
(prefix, suffix)
412+
| ("lpdf" | "lumdf")
413+
when Utils.is_distribution_name (prefix ^ "_lpmf") ->
414+
Semantic_error.returning_fn_expected_wrong_dist_suffix_found loc
415+
(prefix, suffix)
416+
| _ ->
417+
if
418+
is_known_family prefix
419+
&& List.mem ~equal:String.equal
420+
Utils.cumulative_distribution_suffices_w_rng suffix
421+
then
422+
Semantic_error
423+
.returning_fn_expected_undeclared_dist_suffix_found loc
424+
(prefix, suffix)
425+
else
426+
Semantic_error.returning_fn_expected_undeclaredident_found loc
427+
id.name )
428+
| None ->
432429
Semantic_error.returning_fn_expected_undeclaredident_found loc
433-
id.name
434-
|> error )
430+
id.name )
431+
|> error
435432
| _ (* a function *) -> (
436433
match SignatureMismatch.returntype tenv id.name (get_arg_types es) with
437434
| Ok (Void, _) ->

src/middle/Utils.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ let conditioning_suffices =
1414
["_lpdf"; "_lupdf"; "_lupmf"; "_lpmf"; "_cdf"; "_lcdf"; "_lccdf"]
1515

1616
let conditioning_suffices_w_log = conditioning_suffices @ ["_log"]
17-
let cumulative_distribution_suffices = ["cdf"; "lcdf"; "lccdf"]
17+
18+
let cumulative_distribution_suffices =
19+
["cdf"; "lcdf"; "lccdf"; "cdf_log"; "ccdf_log"]
1820

1921
let cumulative_distribution_suffices_w_rng =
2022
cumulative_distribution_suffices @ ["rng"]

0 commit comments

Comments
 (0)