I have C# code: class SomeType {T0, T1} ...

I am confused - do you mean

1
class SomeType <T0, T1>

?

P.s.: where to find how to highligth code syntax in the post?

In your profile select content editor for developers It will give you some additional formatting options

By on 5/11/2009 8:20 AM ()

Nice. Found. Again:

I have C# code:

1
2
3
4
5
6
7
8
9
class SomeType <T0, T1> { // 
... 
public static implicit operator T1(SomeType<T0, T1> st) 
{ 
return st.Get<T1>(); // gets the T1 value from st container 
} 
... 
} 

In C# I can write:

1
2
var st = new SomeType<int,string>(); 
int v = (int)st; 

In F# I write:

1
let v = someType |> SomeType<_,_>.op_Implicit : int 

How to simplify F# code?

By on 5/11/2009 8:32 AM ()

Here's something relatively inscrutable you can try using:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 

open System.Xml.Linq

let xn = XName.op_Implicit("foo")

// a way to shorten what you write

let inline imp< ^a, ^b when ^a : (static member op_Implicit : ^b -> ^a)> arg =

    (^a : (static member op_Implicit : ^b -> ^a) (arg))

// now can write "imp<T,_> v" to implicit convert value v to type T

let xn2 = imp<XName,_> "foo"

// or like this

let xn3 : XName = imp "foo"
By on 5/11/2009 12:12 PM ()

Great. Works.

By the way, where can I read about F# "inline" constructions?

By on 5/12/2009 1:31 AM ()

Offhand I don't know any good docs - I always go and copy examples from the F# source code (prim-types.fs in the source distribution is a useful file to look at for examples of this).

By on 5/12/2009 9:09 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper