Take the 2-minute tour ×

Imagine the following interface in C#:

interface IFoo {
    void Bar();

How can I implement this in F#? All the examples I've found during 30 minutes of searching online show only examples that have return types which I suppose is more common in a functional style, but something I can't avoid in this instance.

Here's what I have so far:

type Bar() =
    interface IFoo with
        member this.Bar() =

Fails with _FS0010:

Unexpected keyword 'void' in expression_.

share|improve this question
add comment

3 Answers

up vote 14 down vote accepted

The equivalent is unit which is syntactically defined as ().

type Bar() =
    interface IFoo with
        member this.Bar () = ()
share|improve this answer
Thanks. I'm enjoying learning F#! –  Drew Noakes Jun 18 '10 at 7:12
@Drew - It is an awesome language. –  ChaosPandion Jun 18 '10 at 13:30
The C# code was a method, not a property. To reproduce this in F#, I believe you need a member with signature unit -> unit. This would be written "member this.Bar () = ()". Without the unit parameter, the F# could would be a property with a getter. –  Jason Jun 18 '10 at 17:18
@Jason - Thanks, it is safe to assume that @Drew implicitly corrected my mistake. –  ChaosPandion Jun 18 '10 at 17:30
@Jason, you're right. Actually my method took arguments (and surprisingly wasn't called Bar!) so I'd messed up transcribing it in the original question. Thanks for pointing this out. I'll edit the question. –  Drew Noakes Jun 18 '10 at 18:19
show 1 more comment

For general info on F# types, see

The basic syntax of F# - types

From that page:

The unit type has only one value, written "()". It is a little bit like "void", in the sense that if you have a function that you only call for side-effects (e.g. printf), such a function will have a return type of "unit". Every function takes an argument and returns a result, so you use "unit" to signify that the argument/result is uninteresting/meaningless.

share|improve this answer
Thanks for the link. I included a quote from the page in your answer. –  Drew Noakes Jun 18 '10 at 10:05
add comment

The return type needs to be (), so something like member this.Bar = () should do the trick

share|improve this answer
To be pedantic, the return type is unit, the only value of that type is spelled (). –  Brian Jun 18 '10 at 8:58
add comment

Your Answer


