Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is 'a in F# [duplicate]

Tags:

f#

While learning F# and reading this page, I found this code:

type MyGenericClass<'a> (x: 'a) =
   do printfn "%A" x

I did not understand the meaning of 'a is it related any how to lifetime concept at rust or something completely different?

like image 201
Hasan A Yousef Avatar asked Dec 02 '25 20:12

Hasan A Yousef


1 Answers

'a is a type parameter, such as T in List<T>. The F# syntax for type parameters is to preface the name of the parameter with the tick mark. In your example, this means that the parameter x can be any type, and it will create a MyGenericClass of that generic type. For example, if you called new MyGenericClass(3), you would get a MyGenericClass<int>.

like image 131
Aaron M. Eshbach Avatar answered Dec 06 '25 11:12

Aaron M. Eshbach



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!