Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

How does the typing system work for F#?

From the article, it looks like it's mostly dynamically typed. Or is it inferred? Or is it something else?

Like, if I write

    let hello value =
      print value
    
    hello "world"
    hello 2
Does that just work?

To me, that'd be a point that might steer me away from the language. Deducible types seem vital to larger and long lived projects.



It's statically typed and inferred.

With regards to your example, the print/printfn (equivalent of Write/WriteLine) functions are a bit funny in F#. They don't actually take bound string values directly. You need to specify the type (which could be a string, a number, obj, etc)

https://learn.microsoft.com/en-us/dotnet/fsharp/language-ref...


F# is a statically typed language with gradual typing and full type inference.

Given

  let hello value =
      printfn "%A" value
    
  hello "world"
  hello 2
The binding "hello" has "'a -> unit" signature where 'a is a generic argument it accepts because the "printfn" binding with a given format specifier is generalized the same way and an unconstrained 'T (here 'a) is the most narrow type inferred for "hello".


> with gradual typing

Isn't gradual typing widely understood to mean "gradual between static and dynamic", which F# certainly isn't?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: