该表达式预计具有类型单位

use*_*938 1 f# f#-interactive unit-type

我有以下代码.在这一行

 if min<=0  then     min <- List.nth list i |>ignore
Run Code Online (Sandbox Code Playgroud)

我有2个错误.首先是0

 This expression was expected to have type
    unit    
but here has type
    int
Run Code Online (Sandbox Code Playgroud)

然后在i

This expression was expected to have type
    unit    
but here has type
    int
Run Code Online (Sandbox Code Playgroud)

*我也看过这个 并尝试忽略,但它不起作用

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
Run Code Online (Sandbox Code Playgroud)

Tom*_*cek 5

您不需要ignore- 如果您正在使用赋值,它将返回unit,因此您没有任何必须忽略的返回值:

if min <= 0 then min <- List.nth list I
Run Code Online (Sandbox Code Playgroud)

也就是说,这不是很实用的方法.因此,查看一些基本的F#书或观看一些演讲可能会帮助您开始使用更多F#风格的语言.