5 people like it.

A return combinator for F#

A combinator that enables real imperative code in F#. Use with caution!

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
#nowarn "42"

let inline ret (x : ^T) = (# "ret" x : ^S #)

let test () : int =
    if false then ret "hello" // your type checker is useless here!
    
    for i = 0 to 100 do
        if i = 42 then ret i
    
    -1

test()
val ret : x:'T -> 'S

Full name: Script.ret
val x : 'T
val test : unit -> int

Full name: Script.test
Multiple items
val int : value:'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------
type int = int32

Full name: Microsoft.FSharp.Core.int

--------------------
type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>
val i : int
Raw view Test code New version

More information

Link:http://fssnip.net/hS
Posted:10 years ago
Author:Eirik Tsarpalis
Tags: return , imperative