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

Function definition with type variables not recognized as a function #270

Closed
jfehrle opened this issue Sep 19, 2020 · 5 comments
Closed

Comments

@jfehrle
Copy link
Collaborator

jfehrle commented Sep 19, 2020

plugin version: 0.92-2020.2

Note the "V" in the structure panel.

type s tr r. defines 3 type variables that are used in the following list of arguments.

image

let rec parser_of_tree : type s tr r. s ty_entry -> int -> int -> (s, tr, r) ty_tree -> r parser_t =
()

@giraud
Copy link
Owner

giraud commented Sep 19, 2020

I don't understand the syntax nor the expectation

@jfehrle
Copy link
Collaborator Author

jfehrle commented Sep 19, 2020

This example is more correct (though still lacking some of the referenced types):

let rec parser_of_tree : type s tr r. s ty_entry -> int -> int -> (s, tr, r) ty_tree -> r parser_t =
  fun entry nlevn alevn -> ()

Defines the function parser_of_tree while explicitly defining the type of the function. The formal parameters are entry, nlevn and alevn. The expectation is that it appears as a function in the structure panel and shows the type there.

The following function definitions are exactly equivalent. The latter gives the type explicitly rather than having the compiler infer its type:

let rec mem x = function
    [] -> false
  | a::l -> compare a x = 0 || mem x l

let rec mem : type a.    a -> a list -> bool    = fun x -> function
    [] -> false
  | a::l -> compare a x = 0 || mem x l

The type notation is similar to what you see in a .mli file (val mem : 'a -> 'a list -> bool).
a list is a polymorphic type: it's a list containing items of type 'a'. The function checks whether an item belongs to a list.

Does that make sense? Any further questions?

@giraud
Copy link
Owner

giraud commented Sep 21, 2020

Thanks, it's clear

@giraud
Copy link
Owner

giraud commented Oct 2, 2020

fixed in 0.93

@giraud giraud closed this as completed Oct 2, 2020
@jfehrle
Copy link
Collaborator Author

jfehrle commented Oct 2, 2020

Looks good, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants