Search code examples
haskellf#functional-programmingocamlnamed-parameters

Parameter names of a function using a functional language such as F#


I have read a book called Clean code. One of the strongest messages that I took from the book is that the code must be readable. I do not understand why functional languages such as F# do not include function parameter names into the intellisense or in the type defintion?

Compare

val copy: string -> string -> unit

with

val copy: sourceFile:string -> destinationFile:string -> unit

What is the best practise in the functional world? Shall we prefer single parameter functions? This is what Clean code promotes. Or shall we use records for all functions of 2+ parameters?

I know that one work-around is to use static member instead of let functions but this is not a functional approach, is it?

EDIT:

Just to give more information:

  • Haskell : addThree :: Int -> Int -> Int -> Int
  • OCaml: Unix.unlink: (string -> unit)

and surely others. They just do not show parameter names in the type definitions.


Solution

  • Or am I completely wrong and it has nothing to do with diferences between functional and imperative programming?

    You're not completely wrong, insofar as functional languages with HM type inference often do not require type annotations at all, or, at least not everywhere.

    Add to this that type expressions are not necessarily function types, hence the concept of a "parameter name" is not applicable. All in all, a name there is just redundant, it does not add any information to a type, and that could be the reason for not allowing it.

    Conversely, in imperative languages, type inference was almost unknown as of late. Thus you must declare everything (in statically typed languages) and so it happens that name and type tend to appear in one place. Moreover, as functions are not first class citiziens, the concept of a function type, let alone an expression that describes a function type is merely unknown.

    Observe that with recent developments (like "lambda" syntax, etc.) the concept of an argument whose type is known already or can be easily inferred also appears in those languages. And when I remember correctly, there is even syntactical easement to avoid long names, the lambda argument is just it or even _