Is Char.chr part of ocaml-core

318 views
Skip to first unread message

Anthony Shaper

unread,
Jan 29, 2014, 4:03:44 PM1/29/14
to ocaml...@googlegroups.com
Hello. I am new to ocaml. I am trying to use the function Char.chr at the top level .As far as I can tell Char.chr should be part of ocaml's standard library. However I get "Unbound value" when I type "Char.chr". I have tried typing "open Core.Std" before calling this but it makes no difference. If I type "Array.length" I get  "- : 'a Core.Std.Array.t -> int = <fun>" which makes me think that the compiler is seeing the core library. Can anyone tell me what I am need to do to make this work. Thanks in advance.
Tony

Malcolm Matalka

unread,
Jan 29, 2014, 4:08:35 PM1/29/14
to ocaml...@googlegroups.com
Works for me (stdlib):

# module M = Char;;
module M :
sig
external code : char -> int = "%identity"
val chr : int -> char
val escaped : char -> string
val lowercase : char -> char
val uppercase : char -> char
type t = char
val compare : t -> t -> int
external unsafe_chr : int -> char = "%identity"
end
# Char.chr 32;;
- : char =
# Char.chr 65;;
- : char = A

Anil Madhavapeddy

unread,
Jan 29, 2014, 4:15:28 PM1/29/14
to ocaml...@googlegroups.com
The Core library redefines some standard library functions to be more consistent.

In this case, Char.chr (from the standard library) is actually Char.of_int or Char.of_int_exn in Core.

Use "Char.of_int" if you want an explicit optional return type, or "Char.of_int_exn" if you don't mind an exception being raised if the integer is not a valid character.  The latter is what the standard library Char.chr function does.

-anil

On 29 Jan 2014, at 21:03, Anthony Shaper <t.za...@gmail.com> wrote:

Hello. I am new to ocaml. I am trying to use the function Char.chr at the top level .As far as I can tell Char.chr should be part of ocaml's standard library. However I get "Unbound value" when I type "Char.chr". I have tried typing "open Core.Std" before calling this but it makes no difference. If I type "Array.length" I get  "- : 'a Core.Std.Array.t -> int = <fun>" which makes me think that the compiler is seeing the core library. Can anyone tell me what I am need to do to make this work. Thanks in advance.
Tony

--
You received this message because you are subscribed to the Google Groups "ocaml-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ocaml-core+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Owen Gunden

unread,
Jan 29, 2014, 4:16:05 PM1/29/14
to ocaml...@googlegroups.com
try:

# Caml.Char.chr 65;;
- : char = A

or

# Char.of_int 65;;
- : Core.Std.Char.t option = Some A



On Wed, Jan 29, 2014 at 4:03 PM, Anthony Shaper <t.za...@gmail.com> wrote:
Hello. I am new to ocaml. I am trying to use the function Char.chr at the top level .As far as I can tell Char.chr should be part of ocaml's standard library. However I get "Unbound value" when I type "Char.chr". I have tried typing "open Core.Std" before calling this but it makes no difference. If I type "Array.length" I get  "- : 'a Core.Std.Array.t -> int = <fun>" which makes me think that the compiler is seeing the core library. Can anyone tell me what I am need to do to make this work. Thanks in advance.
Tony

--

Bruno Deferrari

unread,
Jan 29, 2014, 4:20:25 PM1/29/14
to ocaml...@googlegroups.com
Do you have "open Core.Std" in your ~/.ocamlinit ?

I think Core.Std overrides the Char module and replaces Char.chr with
Char.of_int (which returns a `char option` instead of a char).

> --
> You received this message because you are subscribed to the Google Groups
> "ocaml-core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ocaml-core+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.



--
BD

Anthony Shaper

unread,
Jan 30, 2014, 3:21:00 AM1/30/14
to ocaml...@googlegroups.com
Thanks to everyone who replied.
 I had mixed up the documentation for the standard library and the core.std library and thought Char.chr was in the core.std library.
Both Char.of_int and Caml.Char.chr are working for me. The module function is handy. I was looking for a way to see which functions are defined in a particular module.

-Tony
Reply all
Reply to author
Forward
0 new messages