F# type inferrence issue - f#

I have experienced the following problem while writing a test. Please find a picture bellow.
If I create validateGameExistance function in the unit test project then it works fine.
How could it be solved?

It is hard to give a definite answer (based just on the screenshot), but you can get this kind of error when some of the types involved in the type error are defined in multiple places (so, the type name would look the same, but they would actually be different types in different assemblies).
For example, if the Result<T> type is defined in multiple projects and the function you're calling returns one of them, but your annotation is referring to another one.

Related

Elmish.WPF type conflict: unit -> Model expected where Model provided?

My Elmish.WPF app combines the Elmish.WPF Sample projects ‘NewWindow’ + ‘NewWindow.Core’ which I am adding to a copy of ‘FileDialogsCmdMsg’ + ‘FileDialogsCmdMsg.Core’.
FileDialogsCmdMsg is the basis of this effort and provides the background processing features to which I am adding the ‘NewWindow’ popup window features.
I am stuck on two (2) type-conflicts when WpfProgram.mkProgramWithCmdMsg is called...
...errors on update and bindings calls.
The compiler reports that line has the following errors (see red underlines above)...
...saying that WpfProgram.mkProgramWithCmdMsg expects a unit -> Model but was given a Model where update and bindings are called in the larger type specification.
But here is the type information for the calling function, WpfProgram.mkProgramWithCmdMsg accepting these parameters…
... sorry that is so large.
As you can see, both ‘update’ and ‘bindings’ are producing the Model parameter types expected by WpfProgram.mdProgramWithCmdMsg. And yet we have a unit->Model expected where a Model has been provided type-conflict; why?
Here is more detail on the update type-conflict…
... see how here how here it is claimed a unit->Model is expected when previously you see that update is supposed to expect a Model? Why?
You see the same problem in this detail on the type-conflict with ‘bindings’...
..again showing unit-Model' expected when the correct Model` type parameter is passed.
Here the type information where update is defined…
...and here is the bindings type info…
QUESTION: Why is a "unit->Model expected error reported when the receiving function, WpfProgram.mkProgramWithCmdMsg, and both parameters, update and bindings both respectively provide Model parameters?
Please ask if more detail is needed to get to the bottom of this.
Thanks for your help!
I suspect the problem is with your init function, which (I'm guessing) is a function of type unit -> Model. If this is true, the lambda fun _ -> init, [] binds the concrete type unit -> Model to the 'model type variable. As result, update and bindings also expect the same concrete type, leading to the error message you're seeing.
If I'm correct, you have two choices:
Change init so it is a value of type Model, rather than a function.
Change init so it also returns an empty message list, and then pass init directly to mkProgramWithCmdMsg, rather than passing a lambda.
Note that when you hover over mkProgramWithCmdMsg, the compiler shows you that 'model is indeed bound to unit -> Model, presumably due to the init type mismatch:

No compile time error in Dart when a method is given a parent class in place of its subclass

The following gives a runtime error on the last line but why do I not receive a compile time error?
Why is this? fnSub (last line) accepts a type of Sub but here I'm passing it a type of Parent and it compiles. Ok, I do get a runtime error but I'd have thought this should have given me a compile time error. Is this a bug in Dart or am I misunderstanding the limitations of the type system or have I just gone crazy?
class Parent {}
class Sub implements Parent {
String get blah => "blah";
}
String fnSub(Sub sub) => sub.blah;
String aProblem(Parent parent) => fnSub(parent);
https://dartpad.dev/acd2767cd42371deae0644fa66e8c602
The problem is that implicit-casts are enabled by default in Dart which is a feature trying to make it easier to work around types in Dart by automatically adding type casts in your code base.
This feature will no longer be available when NNBD (Non-nullable by default) are coming where implicit-dynamic also will be gone. Both features can already be disabled today by following this guide: https://dart.dev/guides/language/analysis-options#enabling-additional-type-checks
Personally, I think most projects should disable this two features already since I have seen a lot of people on Stackoverflow being confused about what Dart are doing with the types. So I cannot wait for NNBD so we can get are lot more clear type experience in Dart. And hopefully, the errors from the analyzer will be clear enough for most people so they don't need to get help.
If you disable implicit-casts you code will fail at the following line:
String aProblem(Parent parent) => fnSub(parent);
And with this error:
error - The argument type 'Parent' can't be assigned to the parameter type 'Sub'. - bin\stackoverflow.dart:9:41 - argument_type_not_assignable
If you want to test with Dartpad you can try with the following edition based on a beta version of the next Dart version which has enabled null-safety (and therefore have no implicit-casts): https://nullsafety.dartpad.dev/

cannot traverse the nodes of an AST, while assigning each node an ID

This is more a simple personal attempt to understand what goes on inside Rascal. There must be better (if not already supported) solution.
Here's the code:
fileLoad = |home:///PHPAnalysis/systems/ApilTestScripts/simple1.php|;
fileAST=loadPHPFile(fileLoad,true,false);
//assign a simple id to each node
public map[value,int] assignID12(node N)
{
myID=();
visit(N)
{
case node M:
{
name=getName(M);
myID[name] =999;
}
}
return myID;
}
ids=assignID12(fileAST);
gives me
|stdin:///|(92,4,<1,92>,<1,96>): Expected str, but got value
loadPHPFile returns a node of type: list[Stmt], where each Stmt is one of the many types of statements that could occur in a program (PHP, in my case). Without going into why I'd do this, why doesn't the above code work? Especially frustrating because a very simple example is worked out in the online documentation. See: http://tutor.rascal-mpl.org/Recipes/Basic/Basic.html#/Recipes/Common/CountConstructors/CountConstructors.html
I started a new console, and it seems to work. Of course, I changed the return type from map[value,int] to map[str,int] as it was originally in the example.
The problem I was having was that I may have erroneously defined the function previously. While I quickly fixed an apparent problem, it kept giving me errors. I realized that in Rascal, when you've started a console and imported certain definitions, it (seems)is impossible to overwrite those definitions. The interpreter keeps making reference to the very first definition that you provided. This could just be the interpreter performing a type-check, and preventing unintentional and/or incompatible assignments further down the road. That makes sense for variables (in the typical program sense), but it doesn't seem like the best idea to enforce that on functions (or methods). I feel it becomes cumbersome, because a user typically has to undergo some iterations before he/she is satisfied with a function definition. Just my opinion though...
Most likely you already had the name ids in scope as having type map[str,int], which would be the direct source of the error. You can look in script https://github.com/cwi-swat/php-analysis/blob/master/src/lang/php/analysis/cfg/LabelState.rsc at the function labelScript to see how this is done in PHP AiR (so you don't need to write this code yourself). What this will give you is a script where all the expressions and statements have an assigned ID, as well as the label state, which just keeps track of some info used in this labeling operation (mainly the counter to generate a unique ID).
As for the earlier response, the best thing to do is to give your definitions in modules which you can import. If you do that, any changes to types, etc will be picked up (automatically if the module is already imported, since Rascal will reimport the module for you if it has changed, or when you next import the module). However, if you define something directly in the console, this won't happen. Think of the console as one large module that you keep adding to. Since we can have overloads of functions, if you define the function again you are really defining a new alternative to the function, but this may not work like you expect.

Code analysis in ASP.NET web application

I am using VS 2010; all these days I am confortable runnig code analysis on class libraries.
But for a web application, the UI control names with prefixes like ddl, pnl, etc are causing code analysis warnings as "Correct the spelling...". I googled and think this can be addressed using rulesets; but didn't find a way to suppress these..any pointers ?
You could add them to a custom dictionary.
Why are you using those prefixes?
The most common reason I've seen people give for this is "Hungarian Notation." However, as I've tried to point out in a number of jobs over the years, "you're doing it wrong." Within an IDE like VS 2010, is there any real reason to prefix every DropDownList instance with "ddl"? Both you and the IDE know it's a DropDownList. There's no question or confusion about that.
The idea behind Hungarian Notation isn't to "prefix every variable with a shorthand of its class" but rather to "prefix every variable with what it is." What something is doesn't have to mean its class or type, it's more an idea of what that object intuitively represents. Sure, it's a DropDownList. But what does that DropDownList mean? Is it part of a particular grouping of elements in the UI? That grouping's designation would provide a lot more information than "ddl" ever would.
As an example, say I have an application with various connection strings. In a given method in my DAL, I store one of them in a variable called strConnection. Well, that's adhering to the notation, but it's not telling me anything important. I know it's a string. (I can see its declaration, I can mouse over it in the IDE, etc.) And I know it's a connection string based on its usage. But which one is it? What part of the business does it serve? If instead it was called connstringHR then I could immediately infer that it's the connection string for the HR database.

Is a conversion.properties file always necessary for Struts 2?

I'm reading Struts 2 In Action, and, on the chapter five, a conversion.properties file is created to demonstrate data transfer for multivalued parameters. It includes this line:
Element_weights=java.lang.Double
And there's a list that does not use generics in the Action class:
List weights;
I replaced all this with just
List<Double> weights;
and the type conversion seemed to work just fine. Are there any drawbacks to using generics, any reason for what the authors of the book are doing?
edit: I kept reading and, in fact, generics work, and the authors even recommend it. Why they haven't used it in the first place still puzzles me, nevertheless.
Those types of conversion entries are only needed in pre-generics environments. Definitely use generics if at all possible.

Resources