Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

F# Type declaration possible ala Haskell?

Tags:

haskell

f#

I've looked a number of sources: it seems not possible to declare a type definition in F# ala Haskell:

' haskell type def: myFunc :: int -> int 

I'd like to use this type-def style in F#--FSI is happy to echo back to me:

fsi> let myType x = x +1;;  val myType : int -> int 

I'd like to be explicit about the type def signature in F# as in Haskell. Is there a way to do this? I'd like to write in F#:

//invalid F# myFunc : int -> int myFunc x = x*2 
like image 878
Kevin Won Avatar asked Sep 14 '10 21:09

Kevin Won


1 Answers

The usual way is to do let myFunc (x:int):int = x+1.

If you want to be closer to the haskell style, you can also do let myFunc : int -> int = fun x -> x+1.

like image 69
sepp2k Avatar answered Oct 02 '22 19:10

sepp2k