Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9082559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:35:16+00:00 2026-06-16T20:35:16+00:00

Newbie question. I’m going through the very nice Ocaml ORA book. When I went

  • 0

Newbie question. I’m going through the very nice Ocaml ORA book. When I went to play with the magic_copy example from the section on Marshal, I was closer to a browser than a terminal, so I tried it out in ocsigen’s toplevel in a browser, where I was surprised to get the result:

     (* js_of_ocaml *)
# let ora_magic_copy a =
  let s = Marshal.to_string a [Marshal.Closures] in
  Marshal.from_string s 0;;

val ora_magic_copy : 'a -> 'b = <fun>
# (ora_magic_copy 2 : float) +. 3.1;;

- : float = 5.1

Checking if something has changed between ocaml 2 (current version when the book was written) and ocaml 3.12.1, used by the toplevel installed on my machine and by js_of_ocaml, I tried the same example in the normal toplevel installed on my machine and got the result explained in the book: a segfault due to the typesystem’s trouble with checking Marshaled values.

    (* Linux toplevel *)
# (ora_magic_copy 3: float) +. 2.1;;
Segmentation fault (core dumped)

I’m just curious: why?

I see that in three cases, Marshal.to_string gives the same string: linux marshalling an int, js_of_ocaml marshalling and int, js_of_ocaml marshalling a float. The odd-man-out is linux toplevel marshalling a float.

Is this due to something about js_of_ocaml using javascript’s base types? Or just… undefined behavior?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T20:35:17+00:00Added an answer on June 16, 2026 at 8:35 pm

    Yes, your problem comes from the fact that you are testing on a javascript toplevel.

    When you use the standard ocaml toplevel, the +. operation operates on OCaml floats, i.e. a double boxed inside a block, the two parameters of +. are expected to be pointers to such boxes. In your example, instead of a pointer, you give the OCaml integer 2 (internally, it is represented as 5, i.e. 2 << 1 + 1), so OCaml segfaults while trying to read the double that should be at position 0x5 in memory…

    In the js_of_ocaml browser, floats are just javascript floats, and integers are javascript integers, and +. is the javascript addition, which is able to add integers and floats (by automatically converting integers to floats), because values are tagged by their types.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A newbie question, I obtain a var from a json through a cicle like
newbie question; I have two binary numbers; say for example; 0b11 and 0b00. How
Newbie Question: I successfully get a json collection of books from the server: $.getJSON(/Data/json.txt,
Newbie question: I need to accept a parameter in a form from a method
A newbie question and probably very bingable (had to use that word once :-)),
Newbie question. I want to do something like: SELECT c1,c2,c3 FROM TABLE t1 UNION
Newbie question here. I'd like to be able to specify through data (i.e. an
Newbie Question: I have a dictionary rendering with extra_Context from a method defined in
Newbie question... The objective: I intend to have an HTML text input field as
Newbie question: I just installed VisualSVN Server and created a repository. I noticed that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.