Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/common/Files.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Core
open Std

let stanfunctions_suffix = ".stanfunctions"

Expand All @@ -8,4 +8,4 @@ let remove_dotstan s =
(String.chop_suffix ~suffix:".stan" s)
|> Option.value ~default:s

let is_stanfunctions = String.is_suffix ~suffix:stanfunctions_suffix
let is_stanfunctions = String.ends_with ~suffix:stanfunctions_suffix
2 changes: 1 addition & 1 deletion src/common/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(library
(name common)
(public_name stanc.common)
(libraries core fmt)
(libraries std fmt)
(instrumentation
(backend bisect_ppx)))
12 changes: 6 additions & 6 deletions src/frontend/Semantic_error.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let quoted = SignatureMismatch.quoted
let found_type ppf =
Fmt.pf ppf "@ Instead found type %a." (actual_style UnsizedType.pp)

let rec expected_types : UnsizedType.t Common.Nonempty_list.t Fmt.t =
let rec expected_types : UnsizedType.t Std.Nonempty_list.t Fmt.t =
let ust = expected_style UnsizedType.pp in
fun ppf l ->
match l with
Expand All @@ -23,7 +23,7 @@ let rec expected_types : UnsizedType.t Common.Nonempty_list.t Fmt.t =
| [t1; t2; t3] -> Fmt.pf ppf "%a,@ %a,@ or %a" ust t1 ust t2 ust t3
| t :: ts ->
Fmt.pf ppf "%a,@ %a" ust t expected_types
(ts |> Common.Nonempty_list.of_list_exn)
(ts |> Std.Nonempty_list.of_list_exn)

module TypeError = struct
type t =
Expand Down Expand Up @@ -138,7 +138,7 @@ module TypeError = struct
quoted name name pp_lik_args ellipsis ellipsis pp_laplace_tols
pp_supplied_tys info ()

let rec expected_types : UnsizedType.t Common.Nonempty_list.t Fmt.t =
let rec expected_types : UnsizedType.t Std.Nonempty_list.t Fmt.t =
let ust = expected_style UnsizedType.pp in
fun ppf l ->
match l with
Expand All @@ -147,7 +147,7 @@ module TypeError = struct
| [t1; t2; t3] -> Fmt.pf ppf "%a,@ %a,@ or %a" ust t1 ust t2 ust t3
| t :: ts ->
Fmt.pf ppf "%a,@ %a" ust t expected_types
(ts |> Common.Nonempty_list.of_list_exn)
(ts |> Std.Nonempty_list.of_list_exn)

let pp ppf = function
| IncorrectReturnType (t1, t2) ->
Expand Down Expand Up @@ -210,7 +210,7 @@ module TypeError = struct
Fmt.pf ppf "The inner type in reduce_sum array must be %a.%a"
expected_types
(Stan_math_signatures.reduce_sum_slice_types
|> Common.Nonempty_list.of_list_exn)
|> Std.Nonempty_list.of_list_exn)
found_type ty
| IllTypedReduceSum (name, arg_tys, expected_args, error, _callback_location)
->
Expand Down Expand Up @@ -764,7 +764,7 @@ module StatementError = struct
lt.type_ found_type rt.type_
| IllTypedAssignment (op, lt, rt) ->
let pp_expected_types ppf signatures =
match Common.Nonempty_list.of_list signatures with
match Std.Nonempty_list.of_list signatures with
| None ->
Fmt.pf ppf
"There are no valid right hand sides for the given left hand \
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/Typechecker.ml
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ let check_id cf tenv id =
let loc = id.id_loc in
let (value :: _) =
Env.find tenv (Utils.stdlib_distribution_name id.name)
|> Common.Nonempty_list.of_list
|> Std.Nonempty_list.of_list
|> Option.value_or_thunk ~default:(fun () ->
Semantic_error.ident_not_in_scope loc id.name
(Env.nearest_ident tenv id.name)
Expand Down
3 changes: 1 addition & 2 deletions src/common/Nonempty_list.ml → src/std/Nonempty_list.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ let of_list : _ list -> _ t option = function
| hd :: tl -> Some (hd :: tl)

let of_list_exn : _ list -> _ t = function
| [] ->
ICE.internal_error "Nonempty_list.of_list_exn: empty list" [@coverage off]
| [] -> raise (Invalid_argument "Nonempty_list.of_list_exn: empty list")
| hd :: tl -> hd :: tl
File renamed without changes.
6 changes: 6 additions & 0 deletions src/std/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(library
(name std)
(public_name stanc.std)
(libraries sexplib0)
(instrumentation
(backend bisect_ppx)))
26 changes: 26 additions & 0 deletions src/std/std.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
(** Extensions to the standard library. Most files in the project should begin
[open Std]. *)

(** New modules *)

module Nonempty_list = Nonempty_list

(** OCaml Stdlib with labeled functions *)

include StdLabels
include MoreLabels

(** A few extensions to builtin modules *)

module Option = struct
include Option

let first_some a b = Option.blend Fun.const a b
end

module String = struct
include String

let chop_suffix ~suffix s =
if ends_with ~suffix s then Some (drop_last (length suffix) s) else None
end