Distinctive traits of the functional languages

后端 未结 7 1703
时光取名叫无心
时光取名叫无心 2021-01-30 14:45

It is known that all functional languages share some basic properties like using functions as basic building block for programs with all the consequences like using recursion in

7条回答
  •  隐瞒了意图╮
    2021-01-30 15:22

    I like Chris Conway's answer that states some important axes that help classify different functional languages.

    In terms of features of specific languages, I'll pick F# to call out some features not found in many other FPLs:

    • Active Patterns: a number of FPLs have algebraic data types and pattern-matching, but the F# feature called 'active patterns' lets you define new patterns that allow you to use pattern-matching syntax on arbitrary data.
    • Computation expressions: F# has some beautiful syntactic sugar for authoring monadic code; though the type system cannot express higher-kinded polymorphism (no abstraction over type constructors) so you can't write code for an arbitrary monad M, the code you can write for a fixed monad is very cool, and people write some great comprehensions in the seq{} or async{} monads.
    • Quotations: the usual 'code as data for metaprogramming' bit, though F# has an expressive static type system and rich syntax, and I'm not sure how many non-lisps can do this.

    In terms of general classification, F# is

    • eager (strict, call-by-value; but 'lazy' is a keyword & library and using seq/IEnumerable for some laziness is a common strategy)
    • impure (though syntax biases you towards a purer-by-default style)
    • static (with type inference, so F# often 'feels like scripting', only with type safety)

    Your question is phrased in a way with clear bias against some extra-language pragmatics (e.g. what runtime does it integrate with), but you also ask what "influences the way you develop", and these things do influence that:

    • Visual Studio integration means a great editing experience (e.g. Intellisense)
    • Visual Studio integration means a great debugging experience (e.g. breakpoints/tracepoints, locals, immediate window, ...)
    • REPL for scripting or UI-on-the-fly is hotness (fsi.exe command-line, or "F# Interactive" integrated in VS)
    • .NET integration means for most 'X' there's already a library to do that
    • side tools like FsLex/FsYacc, and integration with MSBuild which makes 'build system' easy

    (I think that trying to separate a language from its runtime and tooling is a mostly academic exercise.)

    So there's a description of lot of distinctive features of one particular language of which I am a fan. I hope others might post similar answers that call out distinctive features of other individual languages.

提交回复
热议问题