I have the following code. in this line
if min<=0 then min <- List.nth list i |>ignore
i have 2 errors.
first in 0 it is
This expression was expected to have type
unit
but here has type
int
and then in i it is
This expression was expected to have type
unit
but here has type
int
* I have also seen this and tried ignore, but it doesn't work
let replace touple2=
let first (a,_,_,_,_)=a
let second (_,b,_,_,_)=b
let third (_,_,c,_,_)=c
let forth (_,_,_,d,_)=d
let fifth (_,_,_,_,e)=e
let sortedlist list= List.sort(list)
let GetMin list=
list |> List.rev |> List.head
let mutable min=list.Head
let mutable i=1
for i in list do
if min<=0 then min <- List.nth list i |>ignore
min
let GetMax list=list |> List.rev |> List.head
let A=first touple2
let B=second touple2
let C=third touple2
let D=forth touple2
let E=fifth touple2
let mylist=[A;B;C;D;E]
let L=sortedlist mylist
let m1=GetMax L
printfn "%d" m1
let touple3= 14,6,18,76,76
replace touple3
You just need parentheses to make your intentions clear to the compiler:
An if without an else in F# is a shorthand for:
It means the result of whatever is inside the
doSomethingblock must be of typeunit. Since an assignment in F# is an expression, your code was returningmin, an int value. This explains your first error.The above happened because, without the parenthesis, the pipe operator was using last parameter os
List.nth, theias the parameter toignore