difference between dune utop and utop











up vote
0
down vote

favorite












If I load the following code in utop, after #require "mparser", it is accepted in the top level and give the signature below



open MParser

let infix p op = Infix (p |>> (fun _ a b -> (`Binop (op, a, b))), Assoc_left)

let operators =
[
[
infix (char '*') `Mul;
infix (char '/') `Div;
];
[
infix (char '+') `Add;
infix (char '-') `Sub;
];
]

let decimal = many1_chars digit |>> int_of_string

let term = (decimal |>> fun i -> `Int i)
let expr s = expression operators term s

let rec calc = function
| `Int i -> i
| `Binop (op, a, b) ->
match op with
| `Add -> calc a + calc b
| `Sub -> calc a - calc b
| `Mul -> calc a * calc b
| `Div -> calc a / calc b


accepted by utop as



val infix :
('a, 'b) MParser.t ->
'c -> ([> `Binop of 'c * 'd * 'd ] as 'd, 'b) MParser.operator = <fun>
val operators :
(_[> `Binop of _[> `Add | `Div | `Mul | `Sub ] * 'a * 'a | `Int of int ]
as 'a, unit)
MParser.operator list list =
[[Infix (<fun>, Assoc_left); Infix (<fun>, Assoc_left)];
[Infix (<fun>, Assoc_left); Infix (<fun>, Assoc_left)]]
val decimal : (int, unit) MParser.t = <fun>
val term : ([> `Int of int ], unit) MParser.t = <fun>
val expr :
unit MParser.state ->
(_[> `Binop of _[> `Add | `Div | `Mul | `Sub ] * 'a * 'a | `Int of int ]
as 'a, unit)
MParser.reply = <fun>
val calc :
([< `Binop of [< `Add | `Div | `Mul | `Sub ] * 'a * 'a | `Int of int ] as 'a) ->
int = <fun>


Now, if I try to load with dune utop a library containing this code as a file/module, I received the following error :



~$ dune utop lib
ocamlc lib/.lib.objs/lib__VariantExemple.{cmi,cmo,cmt} (exit 2)
(cd _build/default && /usr/local/bin/ocamlc.opt -w @a-4-29-40-41-42-44-45-48-58-59-60-40 -strict-sequence -strict-formats -short-paths -keep-locs -g -bin-annot -I lib/.lib.objs -I lib/.lib.objs/.private -I /Users/nrolland/.opam/system/lib/bytes -I /Users/nrolland/.opam/system/lib/mparser -I /Users/nrolland/.opam/system/lib/re -I /Users/nrolland/.opam/system/lib/re/perl -I /Users/nrolland/.opam/system/lib/seq -no-alias-deps -opaque -open Lib -o lib/.lib.objs/lib__VariantExemple.cmo -c -impl lib/variantExemple.ml)
File "lib/variantExemple.ml", line 5, characters 4-13:
Error: The type of this expression,
(_[> `Binop of _[> `Add | `Div | `Mul | `Sub ] * 'a * 'a | `Int of int ]
as 'a, '_weak1)
operator list list, contains type variables that cannot be generalized


It looks like there are some type annotation missing.
I am not too familiar with polymorphic variant type and , is there an obvious solution out ?



I was hoping that sticking the signature part given by utop in an interface would work, but it does not seem to be valid in a .mli file



Edit : the simple solution is to add a closed type annotation.



let operators : ([ `Binop of [ `Add | `Div | `Mul | `Sub ] * 'a * 'a | `Int of int ] as 'a, unit) operator list list  =


I am not sure if there is a reason for why an interactive session and a dune utop lib one-shot loading should behave differently










share|improve this question




























    up vote
    0
    down vote

    favorite












    If I load the following code in utop, after #require "mparser", it is accepted in the top level and give the signature below



    open MParser

    let infix p op = Infix (p |>> (fun _ a b -> (`Binop (op, a, b))), Assoc_left)

    let operators =
    [
    [
    infix (char '*') `Mul;
    infix (char '/') `Div;
    ];
    [
    infix (char '+') `Add;
    infix (char '-') `Sub;
    ];
    ]

    let decimal = many1_chars digit |>> int_of_string

    let term = (decimal |>> fun i -> `Int i)
    let expr s = expression operators term s

    let rec calc = function
    | `Int i -> i
    | `Binop (op, a, b) ->
    match op with
    | `Add -> calc a + calc b
    | `Sub -> calc a - calc b
    | `Mul -> calc a * calc b
    | `Div -> calc a / calc b


    accepted by utop as



    val infix :
    ('a, 'b) MParser.t ->
    'c -> ([> `Binop of 'c * 'd * 'd ] as 'd, 'b) MParser.operator = <fun>
    val operators :
    (_[> `Binop of _[> `Add | `Div | `Mul | `Sub ] * 'a * 'a | `Int of int ]
    as 'a, unit)
    MParser.operator list list =
    [[Infix (<fun>, Assoc_left); Infix (<fun>, Assoc_left)];
    [Infix (<fun>, Assoc_left); Infix (<fun>, Assoc_left)]]
    val decimal : (int, unit) MParser.t = <fun>
    val term : ([> `Int of int ], unit) MParser.t = <fun>
    val expr :
    unit MParser.state ->
    (_[> `Binop of _[> `Add | `Div | `Mul | `Sub ] * 'a * 'a | `Int of int ]
    as 'a, unit)
    MParser.reply = <fun>
    val calc :
    ([< `Binop of [< `Add | `Div | `Mul | `Sub ] * 'a * 'a | `Int of int ] as 'a) ->
    int = <fun>


    Now, if I try to load with dune utop a library containing this code as a file/module, I received the following error :



    ~$ dune utop lib
    ocamlc lib/.lib.objs/lib__VariantExemple.{cmi,cmo,cmt} (exit 2)
    (cd _build/default && /usr/local/bin/ocamlc.opt -w @a-4-29-40-41-42-44-45-48-58-59-60-40 -strict-sequence -strict-formats -short-paths -keep-locs -g -bin-annot -I lib/.lib.objs -I lib/.lib.objs/.private -I /Users/nrolland/.opam/system/lib/bytes -I /Users/nrolland/.opam/system/lib/mparser -I /Users/nrolland/.opam/system/lib/re -I /Users/nrolland/.opam/system/lib/re/perl -I /Users/nrolland/.opam/system/lib/seq -no-alias-deps -opaque -open Lib -o lib/.lib.objs/lib__VariantExemple.cmo -c -impl lib/variantExemple.ml)
    File "lib/variantExemple.ml", line 5, characters 4-13:
    Error: The type of this expression,
    (_[> `Binop of _[> `Add | `Div | `Mul | `Sub ] * 'a * 'a | `Int of int ]
    as 'a, '_weak1)
    operator list list, contains type variables that cannot be generalized


    It looks like there are some type annotation missing.
    I am not too familiar with polymorphic variant type and , is there an obvious solution out ?



    I was hoping that sticking the signature part given by utop in an interface would work, but it does not seem to be valid in a .mli file



    Edit : the simple solution is to add a closed type annotation.



    let operators : ([ `Binop of [ `Add | `Div | `Mul | `Sub ] * 'a * 'a | `Int of int ] as 'a, unit) operator list list  =


    I am not sure if there is a reason for why an interactive session and a dune utop lib one-shot loading should behave differently










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      If I load the following code in utop, after #require "mparser", it is accepted in the top level and give the signature below



      open MParser

      let infix p op = Infix (p |>> (fun _ a b -> (`Binop (op, a, b))), Assoc_left)

      let operators =
      [
      [
      infix (char '*') `Mul;
      infix (char '/') `Div;
      ];
      [
      infix (char '+') `Add;
      infix (char '-') `Sub;
      ];
      ]

      let decimal = many1_chars digit |>> int_of_string

      let term = (decimal |>> fun i -> `Int i)
      let expr s = expression operators term s

      let rec calc = function
      | `Int i -> i
      | `Binop (op, a, b) ->
      match op with
      | `Add -> calc a + calc b
      | `Sub -> calc a - calc b
      | `Mul -> calc a * calc b
      | `Div -> calc a / calc b


      accepted by utop as



      val infix :
      ('a, 'b) MParser.t ->
      'c -> ([> `Binop of 'c * 'd * 'd ] as 'd, 'b) MParser.operator = <fun>
      val operators :
      (_[> `Binop of _[> `Add | `Div | `Mul | `Sub ] * 'a * 'a | `Int of int ]
      as 'a, unit)
      MParser.operator list list =
      [[Infix (<fun>, Assoc_left); Infix (<fun>, Assoc_left)];
      [Infix (<fun>, Assoc_left); Infix (<fun>, Assoc_left)]]
      val decimal : (int, unit) MParser.t = <fun>
      val term : ([> `Int of int ], unit) MParser.t = <fun>
      val expr :
      unit MParser.state ->
      (_[> `Binop of _[> `Add | `Div | `Mul | `Sub ] * 'a * 'a | `Int of int ]
      as 'a, unit)
      MParser.reply = <fun>
      val calc :
      ([< `Binop of [< `Add | `Div | `Mul | `Sub ] * 'a * 'a | `Int of int ] as 'a) ->
      int = <fun>


      Now, if I try to load with dune utop a library containing this code as a file/module, I received the following error :



      ~$ dune utop lib
      ocamlc lib/.lib.objs/lib__VariantExemple.{cmi,cmo,cmt} (exit 2)
      (cd _build/default && /usr/local/bin/ocamlc.opt -w @a-4-29-40-41-42-44-45-48-58-59-60-40 -strict-sequence -strict-formats -short-paths -keep-locs -g -bin-annot -I lib/.lib.objs -I lib/.lib.objs/.private -I /Users/nrolland/.opam/system/lib/bytes -I /Users/nrolland/.opam/system/lib/mparser -I /Users/nrolland/.opam/system/lib/re -I /Users/nrolland/.opam/system/lib/re/perl -I /Users/nrolland/.opam/system/lib/seq -no-alias-deps -opaque -open Lib -o lib/.lib.objs/lib__VariantExemple.cmo -c -impl lib/variantExemple.ml)
      File "lib/variantExemple.ml", line 5, characters 4-13:
      Error: The type of this expression,
      (_[> `Binop of _[> `Add | `Div | `Mul | `Sub ] * 'a * 'a | `Int of int ]
      as 'a, '_weak1)
      operator list list, contains type variables that cannot be generalized


      It looks like there are some type annotation missing.
      I am not too familiar with polymorphic variant type and , is there an obvious solution out ?



      I was hoping that sticking the signature part given by utop in an interface would work, but it does not seem to be valid in a .mli file



      Edit : the simple solution is to add a closed type annotation.



      let operators : ([ `Binop of [ `Add | `Div | `Mul | `Sub ] * 'a * 'a | `Int of int ] as 'a, unit) operator list list  =


      I am not sure if there is a reason for why an interactive session and a dune utop lib one-shot loading should behave differently










      share|improve this question















      If I load the following code in utop, after #require "mparser", it is accepted in the top level and give the signature below



      open MParser

      let infix p op = Infix (p |>> (fun _ a b -> (`Binop (op, a, b))), Assoc_left)

      let operators =
      [
      [
      infix (char '*') `Mul;
      infix (char '/') `Div;
      ];
      [
      infix (char '+') `Add;
      infix (char '-') `Sub;
      ];
      ]

      let decimal = many1_chars digit |>> int_of_string

      let term = (decimal |>> fun i -> `Int i)
      let expr s = expression operators term s

      let rec calc = function
      | `Int i -> i
      | `Binop (op, a, b) ->
      match op with
      | `Add -> calc a + calc b
      | `Sub -> calc a - calc b
      | `Mul -> calc a * calc b
      | `Div -> calc a / calc b


      accepted by utop as



      val infix :
      ('a, 'b) MParser.t ->
      'c -> ([> `Binop of 'c * 'd * 'd ] as 'd, 'b) MParser.operator = <fun>
      val operators :
      (_[> `Binop of _[> `Add | `Div | `Mul | `Sub ] * 'a * 'a | `Int of int ]
      as 'a, unit)
      MParser.operator list list =
      [[Infix (<fun>, Assoc_left); Infix (<fun>, Assoc_left)];
      [Infix (<fun>, Assoc_left); Infix (<fun>, Assoc_left)]]
      val decimal : (int, unit) MParser.t = <fun>
      val term : ([> `Int of int ], unit) MParser.t = <fun>
      val expr :
      unit MParser.state ->
      (_[> `Binop of _[> `Add | `Div | `Mul | `Sub ] * 'a * 'a | `Int of int ]
      as 'a, unit)
      MParser.reply = <fun>
      val calc :
      ([< `Binop of [< `Add | `Div | `Mul | `Sub ] * 'a * 'a | `Int of int ] as 'a) ->
      int = <fun>


      Now, if I try to load with dune utop a library containing this code as a file/module, I received the following error :



      ~$ dune utop lib
      ocamlc lib/.lib.objs/lib__VariantExemple.{cmi,cmo,cmt} (exit 2)
      (cd _build/default && /usr/local/bin/ocamlc.opt -w @a-4-29-40-41-42-44-45-48-58-59-60-40 -strict-sequence -strict-formats -short-paths -keep-locs -g -bin-annot -I lib/.lib.objs -I lib/.lib.objs/.private -I /Users/nrolland/.opam/system/lib/bytes -I /Users/nrolland/.opam/system/lib/mparser -I /Users/nrolland/.opam/system/lib/re -I /Users/nrolland/.opam/system/lib/re/perl -I /Users/nrolland/.opam/system/lib/seq -no-alias-deps -opaque -open Lib -o lib/.lib.objs/lib__VariantExemple.cmo -c -impl lib/variantExemple.ml)
      File "lib/variantExemple.ml", line 5, characters 4-13:
      Error: The type of this expression,
      (_[> `Binop of _[> `Add | `Div | `Mul | `Sub ] * 'a * 'a | `Int of int ]
      as 'a, '_weak1)
      operator list list, contains type variables that cannot be generalized


      It looks like there are some type annotation missing.
      I am not too familiar with polymorphic variant type and , is there an obvious solution out ?



      I was hoping that sticking the signature part given by utop in an interface would work, but it does not seem to be valid in a .mli file



      Edit : the simple solution is to add a closed type annotation.



      let operators : ([ `Binop of [ `Add | `Div | `Mul | `Sub ] * 'a * 'a | `Int of int ] as 'a, unit) operator list list  =


      I am not sure if there is a reason for why an interactive session and a dune utop lib one-shot loading should behave differently







      ocaml variant polymorphic-variants






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 12:54

























      asked Nov 10 at 12:30









      nicolas

      3,89922458




      3,89922458
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          You have _ in front of your types, which suggest your type is weakly polymorphic, and the compiler refuse to let such things live in a compiled object.



          you can get the same result with the mwe :



          let store = ref None


          The toplevel is ok with that as it can be resolved to a monomorphic type later if you evaluate something like store:= Some1, which "monomorphise" the type from _a option ref to int option ref






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238966%2fdifference-between-dune-utop-and-utop%23new-answer', 'question_page');
            }
            );

            Post as a guest
































            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote



            accepted










            You have _ in front of your types, which suggest your type is weakly polymorphic, and the compiler refuse to let such things live in a compiled object.



            you can get the same result with the mwe :



            let store = ref None


            The toplevel is ok with that as it can be resolved to a monomorphic type later if you evaluate something like store:= Some1, which "monomorphise" the type from _a option ref to int option ref






            share|improve this answer

























              up vote
              1
              down vote



              accepted










              You have _ in front of your types, which suggest your type is weakly polymorphic, and the compiler refuse to let such things live in a compiled object.



              you can get the same result with the mwe :



              let store = ref None


              The toplevel is ok with that as it can be resolved to a monomorphic type later if you evaluate something like store:= Some1, which "monomorphise" the type from _a option ref to int option ref






              share|improve this answer























                up vote
                1
                down vote



                accepted







                up vote
                1
                down vote



                accepted






                You have _ in front of your types, which suggest your type is weakly polymorphic, and the compiler refuse to let such things live in a compiled object.



                you can get the same result with the mwe :



                let store = ref None


                The toplevel is ok with that as it can be resolved to a monomorphic type later if you evaluate something like store:= Some1, which "monomorphise" the type from _a option ref to int option ref






                share|improve this answer












                You have _ in front of your types, which suggest your type is weakly polymorphic, and the compiler refuse to let such things live in a compiled object.



                you can get the same result with the mwe :



                let store = ref None


                The toplevel is ok with that as it can be resolved to a monomorphic type later if you evaluate something like store:= Some1, which "monomorphise" the type from _a option ref to int option ref







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 2 days ago









                Julien

                694




                694






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238966%2fdifference-between-dune-utop-and-utop%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest




















































































                    Popular posts from this blog

                    Florida Star v. B. J. F.

                    Error while running script in elastic search , gateway timeout

                    Adding quotations to stringified JSON object values