News for hackers. Stuff that matters.
Re:The Early History of F# [pdf] by logicprog on Friday June 12, 2020 @11:02PM (#23506377)
Wow this is a great comment about a new-to-FP viewpoint on F#. I came to it after I'd already experimented with Haskell and OCaml, used Rust a lot, and been programming with Lisps for years - and I was really impressed with it nevertheless!

I really love the ML-family type systems. They're really great aides to programming, and makes planning really nice. F# has that, plus that usability from C# and TS. It's also, like you said, got a really beautiful syntax IMHO.

I keep coming back to Rust though, because Rust is more general purpose, more performant, and applies better to the stuff I like to work on for my hobby projects. I'd love to use F# more but can't find a reason to at the moment.

TypeScript, Python and Rust have become my comfort languages, but I like Rust the best, because it's got a lot of really nice features from ML languages and a powerful and safe type system.

Re:The Early History of F# [pdf] by kowalgta on Saturday June 13, 2020 @11:49AM (#23510261)
We use F# to build fairly complex portfolio management apps. It's a great match for F# to Javascript transpilers (Fable, WebSharper). It makes it easy to share functions and types between UI and backend and to have powerful type safety. I.e. you change your DB data type and compiler informs you where in the UI you need to make appropriate changes.

This works great with "makes illegal states unrepresentable" approach. It helps to reduce a need for boring unit tests and lets you focus more on expressing domain in code directly.

Re:The Early History of F# [pdf] by bern4444 on Saturday June 13, 2020 @12:24PM (#23510531)
I love this idea too. Is it possible to create a type (in F# or Typescript) to represent an idea like greaterThan2? A value whose type is greaterThan2 would have the obvious constraint the value is always bigger than 2. Having the compiler check such a condition would be awesome.

I kind of can do it for Strings by doing something like this

  type ValidStrings = 'name' | age | 'dob';

The easy way around this is a function to determine this

  function greaterThan2(num) return num > 2;
but it'd be cool to express this level of dynamism as a type.
Re:The Early History of F# [pdf] by kowalgta on Saturday June 13, 2020 @03:22PM (#23511933)
As others mentioned - using smart constructor technique, but not directly as F# has no dependend type capability.

Smart constructor technique works well with 'parse, don't validate' approach [0]. You can push type construction to the boundries of your system so that you can work on a domain code with more precise types. It's not always so rosy however as too much types can become a burden.

[0] https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-va...

Re:The Early History of F# [pdf] by logicprog on Saturday June 13, 2020 @01:11PM (#23510909)
This is called dependent typing, and F# doesn't have it as far as I know. There are other ML-family languages that are capable of it however: Liquid Haskell and Idris are the two I can recall off the top of my head.
Re:The Early History of F# [pdf] by yawaramin on Saturday June 13, 2020 @02:29PM (#23511505)
in F#, yes, in TypeScript, not really. The technique involves using a combo of an opaque nominal type, and a smart constructor:

    (* GreaterThanTwo.fsi *)

    type t

    val make : int -> t option
    val to_int : t -> int

    (* GreaterThanTwo.fs *)

    type t = Value of int

    let make int = if int > 2 then Some (Value int) else None
    let to_int (Value int) = int
Now, `GreaterThanTwo.make x` gives you a value of type `GreaterThanTwo.t option`, meaning it can be `Some` value or `None`. If it's `Some` value, that means it really does contain an int greater than two and you can get that int using `GreaterThanTwo.to_int`.
Re:The Early History of F# [pdf] by logicprog on Saturday June 13, 2020 @01:10PM (#23510896)
This is so true. It's why I love ML-languages: they help me refactor, the help me logically structure my core (through its data types) even before I start, and it helps catch illegal states (if I use the types right) so that unit tests aren't necessary!
Re:The Early History of F# [pdf] by gavinray on Saturday June 13, 2020 @12:37AM (#23506778)
F# has the nicest syntax of any language IMO, it's a shame it's not got a larger mindshare.
Re:The Early History of F# [pdf] by bern4444 on Saturday June 13, 2020 @01:02AM (#23506923)
High praise and interesting to hear this as well from someone else. I feel like I'm on the right track with my analysis in my main comment.

I saw in a different HN post a few weeks ago that jet.com heavily used F# but obviously that's no more.

If a company were using F# and I were looking to switch and all the other stuff was a good match, the language choice would be a big pull for me.

While I use and am learning F# for a side project, there's no substitute for working with one professionally and shipping production code with it. I wish it'd be possible to convince my engineering group to use it.

Re:The Early History of F# [pdf] by Smaug123 on Saturday June 13, 2020 @01:56AM (#23507176)
If your engineering group already uses C# then it might not be such a difficult sell - the two languages are highly interoperable, so you may be able to carve out a particular greenfield project and write it in F# instead of C#. Note, though, that we've found it necessary on project `FooBar` to create specific `FooBar.CSharp` wrapper libraries that C# users can consume; this is because idiomatic API design looks pretty different between F# and C#.

(If you're interested in quant finance in London, I work at G-Research which uses F#; I write almost solely in F# there. You can contact me privately if you like at [email protected].)

Re:The Early History of F# [pdf] by bern4444 on Friday June 12, 2020 @11:46PM (#23506594)
Rust is actually the one other language I'm interested in learning now and is on my list. I have a feeling I'll be in a similar mindset to you once I learn and get some experience with it. I'm interested to compare its syntax to F# as well since to me the F# syntax and design is what I find most compelling.

More broadly there seems to be a big push for updated (perhaps even modern) versions of established languages and I think this is an incredible development to witness.

Rust, Go, Typescript, Scala, Kotlin are all the rage and seem to replace C/C++, javascript, and java. Others might exist for either side as well, this is just off the top of my head. From what I see and read as well functional programming seems to be a lot more popular and a lot of these languages are either built for it or with a good base of support for it. It'd be really interesting to have some hard data to know if this is accurate or just my perception.

My only other exposure to functional programming was an undergrad class required for a CS major (thank gosh it was a requirement too). It used Scheme for the language and Structure and Interpretation of Computer programs for the text book[1]. Looking back, this was the most useful class I took and the ideas have stuck and continue to inform me today. Its the one text book I've gone back to on occasion just to take a look and I've found some versions of it for JS and F# even on github which I use to help learn the language or review the concepts in languages I'm more familiar with.

[1] https://mitpress.mit.edu/sites/default/files/sicp/full-text/...

Re:The Early History of F# [pdf] by shpongled on Saturday June 13, 2020 @01:30AM (#23507060)
I need to give F# a try. Really love the ML style type systems as well, I've played around quite a bit with SML and OCaml, and have been using Rust as my "daily driver" for almost 3 years. Rust definitely feels like the most practical of the MLs