Is their a good F# book that will teach functional programing. Every F# book i see are trying to teach the syntax.
F# is gaining independence from .NET
171–180 of 181 posts
Re: F# is gaining independence from .NET
#172Earlier quoted context omitted.
>functional messes are an order-of-magnitude worse than imperative/OO ones I find them an order of magnitude easier and safer to refactor. And I have done it a few times with production messes I was not familiar with. Immutable values instead of variables and idempotent functions (those not having side effects) makes refactoring a joy and the if it builds it works mantra is pretty much true.
There is pretty broad agreement that pure functions and immutable variables are good to strive for. And since F# doesn't force you to do that even when it is a bad idea, things are quite nice. When mutating state is the simpler thing to do, you can do it. Where things can get weird is when you start passing partially applied functions to other functions, and then you use type inference on function signatures on top o…
The signature never lies. Although I intellectually understood this early on, sometimes when I was in the throws of not understanding code my mind would not understand the signature or somehow would not grasp the important information it was telling me.
When they get a little complex and include generics they can get difficult for humans to parse.
The signature is truth. Stare at it, struggle with it until you get it.
One of the things that attracted me to F# is that every page of code is much more information dense than any language I had previously worked with. While I consider this good, it can also be daunting.
Re: F# is gaining independence from .NET
#173Earlier quoted context omitted.
F# Seqs are .NET IEnumerables, which is to say they are iterators. They're lazy, and you can do things with them that you can't do with "strict" collections. In some ways they are faster than strict collections, in others they are slower. If you plan to be iterating over a Seq multiple times, you should probably turn it into a list or array first, just like in C#. That example without pipes is List.reduce (+) (List.m…
I know what Seq is. C# IEnumerables already have more overhead than iterators in C++/Rust due to historical reasons that can't easily be unwound now, and F# Seq adds a bit more on top, it isn't horrible it is just too bad. The ergonomics of LinkedLists really aren't any different than could be achieved with an array backed List, it just isn't done. I realize part of that is because it facilities immutable data struct…
Re: F# is gaining independence from .NET
#174Earlier quoted context omitted.
F# Seqs are .NET IEnumerables, which is to say they are iterators. They're lazy, and you can do things with them that you can't do with "strict" collections. In some ways they are faster than strict collections, in others they are slower. If you plan to be iterating over a Seq multiple times, you should probably turn it into a list or array first, just like in C#. That example without pipes is List.reduce (+) (List.m…
I know what Seq is. C# IEnumerables already have more overhead than iterators in C++/Rust due to historical reasons that can't easily be unwound now, and F# Seq adds a bit more on top, it isn't horrible it is just too bad. The ergonomics of LinkedLists really aren't any different than could be achieved with an array backed List, it just isn't done. I realize part of that is because it facilities immutable data struct…
Re: F# is gaining independence from .NET
#175F# on the JVM would be a game changer
Re: F# is gaining independence from .NET
#176Re: F# is gaining independence from .NET
#177Earlier quoted context omitted.
I think one problem is (was?) winforms is not available in f#. (which is c# unique selling point i. m. h. o.)
Are you thinking of something else than winforms? I believe winforms and WPF has always been usable but not with the visual designer tooling in visual studio. UWP has been trickier though to my knowledge.
Re: F# is gaining independence from .NET
#178Earlier quoted context omitted.
IMHO it's tooling. The industry has spend decades to help you to deal with the kind of mess OO tends to produce. The tooling isn't anywhere close when you have to deal with a mess of functions returning functions that return functions.
> a mess of functions returning functions that return functions. That is just a curried function with three arguments. The bigger problem is that programmers still have to understand how Hindley-Milner type inference works to figure out type errors. This gets worse when you add in type classes, dependent types and (Yog-Sothoth help you) lenses. Your point is still true. For any language, it is important to have an ID…
let createMemoizer f =
let cache = Dictionary()
let f' = fun x ->
match cache.TryGetValue(x) with
| (true,value) -> value
| (false, _) ->
let result = f x
do cache.[x]
The signature is ```createMemoizer (f:'a->'b) -> 'a->'b```, which is not very telling, especially if it is returned by yet another function, so that even the createMemoizer name is lost. In classic OO, I'd just get a Memoizer object that carries vital documenation and what not with itself, as it is passed around. It's no even that much longer, it's just not as elegant to use. class Memoizer {
Dictionary cache = new Dictionary();
Func f;
/* ... */
public TOUTPUT Invoke(TINPUT parameter) {
if (!cache.TryGetValue(parameter, out var result)) {
result = f(parameter);
cache[parameter] = result;
}
return result;
}
}Re: F# is gaining independence from .NET
#179Earlier quoted context omitted.
F# Seqs are .NET IEnumerables, which is to say they are iterators. They're lazy, and you can do things with them that you can't do with "strict" collections. In some ways they are faster than strict collections, in others they are slower. If you plan to be iterating over a Seq multiple times, you should probably turn it into a list or array first, just like in C#. That example without pipes is List.reduce (+) (List.m…
I know what Seq is. C# IEnumerables already have more overhead than iterators in C++/Rust due to historical reasons that can't easily be unwound now, and F# Seq adds a bit more on top, it isn't horrible it is just too bad. The ergonomics of LinkedLists really aren't any different than could be achieved with an array backed List, it just isn't done. I realize part of that is because it facilities immutable data struct…
It still isn't as simple in implementation as a linked list, but they really shouldn't be used except as immutable data structures. That's the only reason I use them.
Phillip mentions this below but F#'s Seq does not add overhead to IEnumerable, it is exactly the same as IEnumerable.
I'm curious about what you see as the unavoidable overhead in IEnumerables, though.
Re: F# is gaining independence from .NET
#180Earlier quoted context omitted.
To the extent that I understand your complaint, there is a functional architecture that alleviates this concern: arrowized functional reactive programming. https://blog.jle.im/entry/intro-to-machines-arrows-part-1-st... talks about it.
Does this solve the problem though? I'll be honest, I'm not very familiar with Haskell (and frankly only casually use FP in general), but I don't see how the pattern in your link alleviates my concern. The problem (truly the problem) is about _where_ one defines behavior. It's the expression problem (EP) at its core. A FP approach separates data and behavior in a way that makes adding new behaviors to the same data t…