Questions tagged [value-restriction]

In functional programming, in particular the ML programming language family, the value restriction means that declarations are only polymorphically generalized if they are syntactic values (also called non-expansive).

In functional programming, in particular the ML programming language family, the value restriction means that declarations are only polymorphically generalized if they are syntactic values (also called non-expansive). The value restriction prevents reference cells from holding values of different types and preserves type safety.

Some interesting notes on value restriction

http://en.wikipedia.org/wiki/Value_restriction

For F#

Automatic Generalization
Subtyping, overloading and inline functions
Defining the value restriction
Imperative programming necessitates the value restriction

41 questions
1
vote
3 answers

How to make my function generic

let csvList startDelim endDelim lst memF = let listIter (listStr: string) item = if listStr.Length > 0 then listStr + "," + (memF item) else memF item …
akaphenom
  • 6,728
  • 10
  • 59
  • 109
1
vote
1 answer

value restriction error details

let empties = Array.create 100 [] Gives a value restriction error: error FS0030: Value restriction. The value 'empties' has been inferred to have generic type val empties : '_a list []. Either define 'empties' as a simple data term, make it a…
Bad
  • 4,967
  • 4
  • 34
  • 50
1
vote
1 answer

Value restriction in F#

I've got an F# assignment where I am trying to compute the transpose of a matrix. Simple enough, but I keep getting a value restriction error and I cannot figure out why. I consulted many of the VR error questions that are out there, but I'm still…
filpa
  • 3,651
  • 8
  • 52
  • 91
1
vote
1 answer

Why does value restriction happen with MergeSort function?

I have a very simple MergeSort implementation on List. /// Divide the list into (almost) equal halves let rec split = function | [] -> [], [] | [x] -> [x], [] | x1::x2::xs -> let xs1, xs2 = split xs x1::xs1,…
pad
  • 41,040
  • 7
  • 92
  • 166
0
votes
0 answers

How to select individuals with one property value with SWRL rules using Protègè

I'm modelling an ontology about Pokèmon using Protègè 5.5.0 and it's reasoner Hermit (Pellet doesn't work and makes the program crash). I created some rules about pokemon types' effectiveness. I first created a rules stating that, for example, a…
AC24
  • 1
0
votes
2 answers

XSD to check if all element occurrence contains the same value in the whole XML file

I am looking for a XSD to validate if a XML containing file elements with many payments have the same currency. Example: 2020-09-28 11
Filipe Santos
  • 61
  • 2
  • 9
0
votes
1 answer

reasonml type higher order function

given the following module the compiler raises an error 41 │ }; 42 │ 43 │ module TestB = { 44 │ let minFn = (a, b) => a < b ? a : b; . │ ... 54 │ let max = reduceList(maxFn); 55 │ }; 56 │ 57 │ // module Number = { The…
hesxenon
  • 501
  • 3
  • 12
0
votes
2 answers

F#: arithmetic operator and loss of polymorphism (value restriction?)

This code doesn't compile: let f = fun x y -> x <<< y // bit shift let g = fun x y -> x <<< y [] let main _ = printfn "%d" <| f 1 10 printfn "%d" <| f 1L 10 // error printfn "%d" <| g 1L 10 0 (7,21): error FS0001: This…
0
votes
2 answers

Is it possible to write a weakly polymorphism function without involving ref or partial application?

let remember = let cache = ref None in (fun x -> match !cache with | Some y -> y | None -> cache := Some x; x) is weakly polymorphism, but involving ref. Any ways to write a weakly polymorphism function without involving…
Jackson Tale
  • 25,428
  • 34
  • 149
  • 271
0
votes
2 answers

Define sum of square without defining parameter

I want to define sumOfSquares without explicity using parameter, relying instead on functional composition Here's my code below let sumOfSquares = Seq.map (fun n -> n * n) >> Seq.sum However, I got the following error stdin(80,5): error FS0030:…
OnesimusUnbound
  • 2,886
  • 3
  • 30
  • 40
-1
votes
1 answer

SQL - list all data if a column is empty

I'm trying to write a WHERE clause, which returns all data if the column is empty. I have a csv file (static_table) which consists of: If the permission is empty that means that the user will need to see everything. So if the hvfg23 user is logged…
Teddy
  • 9
  • 1
  • 9
1 2
3