Questions tagged [automatic-generalization]

This is for the F# feature which automatically generalizes the arguments and types of functions so that they work with multiple types when this is possible.

This is for the F# feature which automatically generalizes the arguments and types of functions so that they work with multiple types when this is possible. The F# compiler, when it performs type inference on a function, determines whether a given parameter can be generic. The compiler examines each parameter and determines whether the function has a dependency on the specific type of that parameter. If it does not, the type is inferred to be generic.

10 questions
9
votes
2 answers

Why is F# compiler sometimes incorrectly generalizing functions?

I ran into some unexpected behavior from the F# compiler recently. I was able to find a workaround, but the original behavior baffles me and I wanted to see if anyone can help me understand what causes it. A function that I had defined as…
9
votes
3 answers

Generic functions in F#

I'm still trying to wrap my head around how F# generalizes (or not) functions and types, and there's a case that's bugging me: let min(a, b) = if a < b then a else b let add(a, b) = a + b let minInt = min(3, 4) let minFloat = min(3.0, 4.0) //…
Asik
  • 21,506
  • 6
  • 72
  • 131
7
votes
2 answers

F# automatic generalization and performance

I ran into an unexpected code optimization recently, and wanted to check whether my interpretation of what I was observing was correct. The following is a much simplified example of the situation: let demo = let swap fst snd i = if i =…
Mathias
  • 15,191
  • 9
  • 60
  • 92
4
votes
1 answer

Why is automatic generalization sometimes inferring overly specific types?

Some function usages don't compile when one side of an operator has a known type and the other doesn't. One example is with units of measure: let inline multiplyWithFive x = 5. * x type [] myUnit let test = multiplyWithFive 3. //…
Vandroiy
  • 6,163
  • 1
  • 19
  • 28
4
votes
1 answer

Intel Fortran Compiler option for automatic dependency generation

Is there an option for automatic dependency generation for INTEL Fortran Compiler, like the "-MM" option of c/c++ compiler, we can use in makefile?
3
votes
1 answer

How to implement automatic generalization in a simple function

I created the following operator to help with safe division. let (/!) a b = if b = 0 then 0 else a / b The problem is that it only works with integers, and I'd like this function to work with any numeric primitive (int, float, decimal,…
Joe
  • 776
  • 7
  • 20
1
vote
2 answers

Generalizing functions in F#

I need a function that produces primes in F#. I found this: let primesSeq = let rec nextPrime n p primes = if primes |> Map.containsKey n then nextPrime (n + p) p primes else primes.Add(n, p) let rec…
LA.27
  • 1,888
  • 19
  • 35
0
votes
0 answers

Automatic rule generation from categorical features and categorical output

I have a dataset with all the features and the required output with categorical values. I would like to select combinations(multiple - can be as high as over 100 combinations) of features (in order), that best describes the final output. Are there…
0
votes
2 answers

how to reference | python| syntax/logic

i wrote python code to organize 40G's of music, but it only works on my computer, so i wanted to generalize the code so it works in what ever directory in what ever computer. import os #imports os functions import eyed3 #imports eyed3…
0
votes
1 answer

Generalizing a User Interface of an application

I am working in C language and creating applications for an embedded device. These applications mainly include capturing data and storing it into a database for performing an enrollment. This involves lot of widgets like frames, buttons,…
john
  • 1,323
  • 2
  • 19
  • 31