Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

polymorphic function in a mutable struct #3810

Closed
vicuna opened this issue Oct 12, 2005 · 2 comments
Closed

polymorphic function in a mutable struct #3810

vicuna opened this issue Oct 12, 2005 · 2 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Oct 12, 2005

Original bug ID: 3810
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Full_Name: Vincent Poirriez
Version: 3.08.4
OS: debian
Submission from: proxy-rech.univ-valenciennes.fr (193.50.193.25)

Is this normal? I found that really strange:

let t = [| List.sort|];;

val t : (('_a -> '_a -> int) -> '_a list -> '_a list) array = [||]

t.(0) compare [1.;2.;3.];;

  • : float list = [1.; 2.; 3.]

t;;

  • : ((float -> float -> int) -> float list -> float list) array = [||]

t.(0) compare [1;2;3];;

Characters 15-16:
t.(0) compare [1;2;3];;
^
This expression has type int but is here used with type float

Amicalement
Vincent

@vicuna
Copy link
Author

vicuna commented Oct 12, 2005

Comment author: administrator

Cher Vincent,

Writing in English for posterity in the bug-tracking system:

Is this normal? I found that really strange:

Entirely normal: it's the "monomorphic reference" restriction.

let t = [| List.sort|];;

val t : (('_a -> '_a -> int) -> '_a list -> '_a list) array = [||]

Note that '_a above is a weak type variable, not universally quantified.

You can preserve the polymorphism of List.sort by using explicit
deep universal quantification:

type sorting_function =

{ sortfun: 'a. ('a -> 'a -> int) -> 'a list -> 'a list };;

type sorting_function = {
sortfun : 'a. ('a -> 'a -> int) -> 'a list -> 'a list;
}

let t = [| {sortfun = List.sort} |];;

val t : sorting_function array = [|{sortfun = }|]

t.(0).sortfun compare [1.;2.;3.];;

  • : float list = [1.; 2.; 3.]

t.(0).sortfun compare [1;2;3];;

  • : int list = [1; 2; 3]

Amitiés,

  • Xavier

@vicuna vicuna closed this as completed Oct 12, 2005
@vicuna
Copy link
Author

vicuna commented Oct 13, 2005

Comment author: administrator

Full_Name: Vincent Poirriez
Version: 3.08.4
OS: debian
Submission from: proxy-rech.univ-valenciennes.fr (193.50.193.25)

Is this normal? I found that really strange:

let t = [| List.sort|];;

val t : (('_a -> '_a -> int) -> '_a list -> '_a list) array = [||]

t.(0) compare [1.;2.;3.];;

  • : float list = [1.; 2.; 3.]

t;;

  • : ((float -> float -> int) -> float list -> float list) array = [||]

t.(0) compare [1;2;3];;

Characters 15-16:
t.(0) compare [1;2;3];;
^
This expression has type int but is here used with type float

Amicalement
Vincent

Yes, this is normal: it is explained in the large in the language's FAQ.

Regards,

--
Pierre Weis

INRIA, Projet Cristal, http://pauillac.inria.fr/~weis

@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant