f# - Compiler can't tell which record type with duplicate fields should be the function parameter type -


In my program there are some record types with some field names (each record type means something different). The compiler says that the function parameter matching this record size should be declared as last, even if I declare events in the record with clear field names, and always going through a constant type in each function I am

Is there a proper way to deal with this? I know that I can put a type of annotation on the function, but I think if I am working correctly, then I will not need to fight the compiler with type annotation.

Minimum code problem:

  type type1 = {x: int} type type2 = {x: int} let's getX t = tx getX {type1.x = 1} | & Gt;  

Compiler output:

  $ fsharpc --nologo test.fs /tmp/typetest/test.fs(7,6): error FS0001: this The expression was expected to be type type 2 but type type1 here  

there are some Methods of Nearby:

  1. Type the annotation as you suggested:

      Let getx (t: type1) = tx < / Code> 
  2. Set the getX before the defined type:

      type1 = {x: int} Type letx t = tx type2 = {x: int}  
  3. Do not explicitly specify the type when calling the function:

      getX {x = 1}  

Which of these The little option depends on the exact situation in the 'right' way.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -