janestreet / base

Standard library for OCaml
MIT License
859 stars 125 forks source link

Bizzare type signatures in utop #39

Closed ghost closed 4 years ago

ghost commented 6 years ago

This may be a utop issue, I have no idea.

Here's an example of Base functions that showup with weird sexp type signatures in utop

─( 13:54:27 )─< command 0 >─────────────────────────────────────────────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # List.map;;
- : 'a sexp_list -> f:('a -> 'b) -> 'b sexp_list = <fun>
─( 13:54:34 )─< command 1 >─────────────────────────────────────────────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # String.split_on_chars;;
- : Base.string -> on:char sexp_list -> Base.string sexp_list = <fun>
─( 13:55:42 )─< command 2 >─────────────────────────────────────────────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # Hashtbl.of_alist_exn;;
- : ('a, 'b, ('a * 'b) sexp_list -> ('a, 'b) Hashtbl.t)
    Hashtbl_intf.create_options_with_first_class_module
= <fun>

~/.ocamlinit:

#use "topfind";;
#thread;;
#camlp4o;;
#require "core.top";;

(* Added by OPAM. *)
let () =
  try Topdirs.dir_directory (Sys.getenv "OCAML_TOPLEVEL_PATH")
  with Not_found -> ()
;;

open Base

lewis@1711:~/code/nw2018$ opam list

Installed packages for 4.05.0:

base v0.10.0 Full standard library replacement for OCaml base-bigarray base Bigarray library distributed with the OCaml compiler base-bytes base Bytes library distributed with the OCaml compiler base-num base Num library distributed with the OCaml compiler base-threads base Threads library distributed with the OCaml compiler base-unix base Unix library distributed with the OCaml compiler bin_prot v0.10.0 A binary protocol generator biniou 1.2.0 Binary data format designed for speed, safety, ease of use and backward compatibility as protocols evolve camomile 0.8.7 A comprehensive Unicode library cmdliner 1.0.2 Declarative definition of command line interfaces for OCaml conf-m4 1 Virtual package relying on m4 conf-which 1 Virtual package relying on which configurator v0.10.0 Helper library for gathering system configuration core v0.10.0 Industrial strength alternative to OCaml's standard library core_kernel v0.10.0 Industrial strength alternative to OCaml's standard library cppo 1.6.4 Equivalent of the C preprocessor for OCaml programs easy-format 1.3.1 High-level and functional interface to the Format module of the OCaml standard library fieldslib v0.10.0 Syntax extension to define first class values representing record fields, to get and set record fields, iterate and fold over all fields of a r jane-street-headers v0.10.0 Jane Street C header files jbuilder 1.0+beta18 Fast, portable and opinionated build system lambda-term 1.12.0 Terminal manipulation library for OCaml lwt 3.2.1 Promises, concurrency, and parallelized I/O lwt_react 1.1.0 Helpers for using React with Lwt merlin 3.0.5 Editor helper, provides completion, typing and source browsing in Vim and Emacs num 0 The Num library for arbitrary-precision integer and rational arithmetic ocaml-compiler-libs v0.10.0 OCaml compiler libraries repackaged ocaml-migrate-parsetree 1.0.7 Convert OCaml parsetrees between different versions ocamlbuild 0.12.0 OCamlbuild is a build system with builtin rules to easily build most OCaml projects. ocamlfind 1.7.3-1 A library manager for OCaml ocp-build 1.99.20-beta Project builder for OCaml ocp-indent 1.6.1 A simple tool to indent OCaml programs octavius 1.2.0 Ocamldoc comment syntax parser ppx_assert v0.10.0 Assert-like extension nodes that raise useful errors on failure ppx_ast v0.10.0 OCaml AST used by Jane Street ppx rewriters ppx_base v0.10.0 Base set of ppx rewriters ppx_bench v0.10.0 Syntax extension for writing in-line benchmarks in ocaml code ppx_bin_prot v0.10.0 Generation of bin_prot readers and writers from types ppx_compare v0.10.0 Generation of comparison functions from types ppx_core v0.10.0 Standard library for ppx rewriters ppx_custom_printf v0.10.0 Printf-style format-strings for user-defined string conversion ppx_derivers 1.0 Shared [@@deriving] plugin registry ppx_driver v0.10.2 Feature-full driver for OCaml AST transformers ppx_enumerate v0.10.0 Generate a list containing all values of a finite type ppx_expect v0.10.0 Cram like framework for OCaml ppx_fail v0.10.0 Add location to calls to failwiths ppx_fields_conv v0.10.0 Generation of accessor and iteration functions for ocaml records ppx_hash v0.10.0 A ppx rewriter that generates hash functions from type expressions and definitions ppx_here v0.10.0 Expands [%here] into its location ppx_inline_test v0.10.0 Syntax extension for writing in-line tests in ocaml code ppx_jane v0.10.0 Standard Jane Street ppx rewriters ppx_js_style v0.10.0 Code style checker for Jane Street Packages ppx_let v0.10.0 Monadic let-bindings ppx_metaquot v0.10.0 Write OCaml AST fragment using OCaml syntax ppx_optcomp v0.10.0 Optional compilation for OCaml ppx_optional v0.10.0 Pattern matching on flat options ppx_pipebang v0.10.0 A ppx rewriter that inlines reverse application operators |> and |! ppx_sexp_conv v0.10.0 Generation of S-expression conversion functions from type definitions ppx_sexp_message v0.10.0 A ppx rewriter for easy construction of s-expressions ppx_sexp_value v0.10.0 A ppx rewriter that simplifies building s-expressions from ocaml values ppx_tools 5.0+4.05.0 Tools for authors of ppx rewriters and other syntactic tools ppx_tools_versioned 5.1 A variant of ppx_tools based on ocaml-migrate-parsetree ppx_traverse v0.10.0 Automatic generation of open-recursion classes ppx_traverse_builtins v0.10.0 Builtins for Ppx_traverse ppx_type_conv v0.10.0 Support Library for type-driven code generators ppx_typerep_conv v0.10.0 Generation of runtime types from type declarations ppx_variants_conv v0.10.0 Generation of accessor and iteration functions for ocaml variant types re 1.7.1 RE is a regular expression library for OCaml react 1.2.1 Declarative events and signals for OCaml result 1.3 Compatibility Result module sexplib v0.10.0 Library for serializing OCaml values to and from S-expressions spawn v0.10.1 Spawning sub-processes stdio v0.10.0 Standard IO library for OCaml topkg 0.9.1 The transitory OCaml software packager typerep v0.10.0 typerep is a library for runtime types. utop 2.1.0 Universal toplevel for OCaml variantslib v0.10.0 Part of Jane Street's Core library yojson 1.4.1 Yojson is an optimized parsing and printing library for the JSON format zed 1.6 Abstract engine for text edition in OCaml

bcc32 commented 6 years ago

I get these type signatures in merlin output too, I don't think it's a utop issue.

yminsky commented 6 years ago

I believe this is because of issues with the short-paths heuristic in the compiler. There is a feature in progress to resolve this. I'm not sure it will hit the 4.07 timeline, though.

y

On Mon, Mar 5, 2018 at 12:24 PM, Aaron Zeng notifications@github.com wrote:

I get these type signatures in merlin output too, I don't think it's a utop issue.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/janestreet/base/issues/39#issuecomment-370495599, or mute the thread https://github.com/notifications/unsubscribe-auth/AArqJrWSNQ2VZlztc5e65AT3zJ4dZIWeks5tbXSwgaJpZM4SbJqZ .

hhugo commented 6 years ago

I do not see this issue with base. I could reproduce this issue with core_kernel and core. @lpw25, will this be solved with the new short path.

lpw25 commented 6 years ago

It should be, although partly by luck. Really ppx_sexp_conv should move to using attributes instead of special type names, then we could remove the sexp_list type from the environment.

copy commented 6 years ago

ppx_sexp_conv already seems to support a generalisation of sexp_{list,bool,array,option}, see defaults. The next step is to remove the 'a sexp_list = 'a list alias from Base and replace the uses of the special type names with the new attributes.

Merlin also shows sexp_{list,bool,array,option} instead of {list,bool,array,option}, for example when running MerlinTypeOf on Base.List.

vzaliva commented 5 years ago

any workarounds?

yminsky commented 5 years ago

We're working on changing ppx_sexp_conv so that these type definitions become unnecessary. That should fix the problem.

kevinji commented 5 years ago

See f7770efe71c9defdce3f8977088cba49d908e351.

seliopou commented 4 years ago

This issue is old enough that it's likely stale. And indeed I checked some of the examples cited above and indeed the special sexp_ types are no longer being used, and the type alias for the hash table constructor has been expanded.