Increment value in F#

前端 未结 3 458
故里飘歌
故里飘歌 2021-01-17 13:11

Maybe it\'s too simple thing to do, but I can\'t find any answer in the web
I\'m try to Increment value in F# (like count++ in C#).
I don\'t want to use

3条回答
  •  孤街浪徒
    2021-01-17 13:50

    You can't simulate a postincrement operator but you can do preincrement

    let inline (+=) (x : byref<_>) y = x <- x + y
    
    let mutable a = 0
    &a += 1
    

    or

    let inline incv (x : byref<_>) = x <- x + LanguagePrimitives.GenericOne; x
    
    let mutable b = 0
    incv &b
    

提交回复
热议问题