Live data from Hacker News

The general value of typed functional programming lies in leaving no edge cases

np.reddit.com

61–70 of 172 posts

Re: The general value of typed functional programming lies in leaving no edge cases

#61
post #45

Conversely, it's also one of the biggest pain-points when throwing together a quick prototype.

Then here's where typescript shines. To be able to move fluidly between no static checks of JavaScript and strong-ish type safety of typescript without too much work.

Then again, it's not always without hiccups.

Re: The general value of typed functional programming lies in leaving no edge cases

#62
post #60
post #57

For me the value of typed functional programming has been it's ability to encode business logic in to the type system and thus validate some of my logic at compile time.

What's specifically functional about this advantage. Can't you encode the buisness logic into types in non-functional languages as well?

The type systems that are common in functional languages are usually more flexible and useful than what you find in most other common languages (in particular, usually more useful than the type systems of common object oriented languages).

Re: The general value of typed functional programming lies in leaving no edge cases

#63
post #44

I am not sure this is the only value, but it is generally true. And this is one of the great advantages of haskell. By the way, now that I know some haskell, I see this edge case sloppiness all the time and it is really annoying. For example, here is something that annoyed me just recently. You go to yahoo finance and there they will show you the revenues of a company as well as the revenue growth from past year. But…

Ive noticed other languages with this feature, they call them optional types, you can pass in a null or a type value.

/s slightly, maybe more snarky, but seriously, optional types are way overhyped. Null objects are far more useful than optionals. Optionals tend to leak all over the show.

Re: The general value of typed functional programming lies in leaving no edge cases

#64
post #19
post #14

Earlier quoted context omitted.

You can use a functional style in those languages as well. Or do you mean with Rust's borrow checker you have less mutability to worry about?

If you have a Rust enum with Color{Red,Green,Blue), if for some reason you update to Color{Red,Green,Blue,Yellow}, the rustc compiler will force you to manage the new Yellow case wherever you want to "match" a pattern on Color, so overall you have less chance to forget to manage the new case everywhere. This kind of error is not managed by a C or C++ compiler (as far as I know). But from my understanding, this is not…

Many people have their compilers set to enforce these things, and many of us go a step further and make our compiler warnings into errors so it’s impossible to build a program with these errors. That’s very commonplace, and C++ does it just fine. Missing cases in enums and at least 100 other very common matters can be checked at compile time in C++, the only difference is that it’s not the default as it is in some other languages.

Re: The general value of typed functional programming lies in leaving no edge cases

#65
post #51

They say that, and then turn around and show an example using IEEE-754 Doubles. You've got two infinities and two "not a number" values. What your type system thinks is a number isn't even necessarily a number. Maybe. Better be sure to call the "isNaN()" and "isInfinite()" methods all over the place, because those are the worst edge cases of all and your language provides no help in detecting or avoiding them. It's l…

There are some research languages that deal with this.

Re: The general value of typed functional programming lies in leaving no edge cases

#66
post #51

They say that, and then turn around and show an example using IEEE-754 Doubles. You've got two infinities and two "not a number" values. What your type system thinks is a number isn't even necessarily a number. Maybe. Better be sure to call the "isNaN()" and "isInfinite()" methods all over the place, because those are the worst edge cases of all and your language provides no help in detecting or avoiding them. It's l…

Haskell is so much better, and you would learn that with about 5 minutes learning about the number types

Haskell still doesn't track NaN in the type system.

Re: The general value of typed functional programming lies in leaving no edge cases

#67
post #60
post #57

For me the value of typed functional programming has been it's ability to encode business logic in to the type system and thus validate some of my logic at compile time.

What's specifically functional about this advantage. Can't you encode the buisness logic into types in non-functional languages as well?

The word “type“ has a fairly different meaning in functional programming compared to object oriented programming. At a very shallow level, they have some similarities. But the way they are used is vastly different between the two paradigms.

Re: The general value of typed functional programming lies in leaving no edge cases

#68
post #44

I am not sure this is the only value, but it is generally true. And this is one of the great advantages of haskell. By the way, now that I know some haskell, I see this edge case sloppiness all the time and it is really annoying. For example, here is something that annoyed me just recently. You go to yahoo finance and there they will show you the revenues of a company as well as the revenue growth from past year. But…

> You can create a type that can encompass all kinds of edge cases and information about them.

This is not unique to functional programming languages.

Haskell was definitely a trailblazer for this, but plenty of conventional languages support this now with relative ease.

Re: The general value of typed functional programming lies in leaving no edge cases

#69
post #2

Edge case removed: for i=0 to 10 {print(a[i])} vs for x in a {print(x)} With functional programming it gets even better: a.filter {}.map{print} Pseudo code, of course. I list several “functional“ examples in Swift here: https://github.com/melling/SwiftCookBook/blob/master/functio... Functional programming is also a higher level language. map, reduce,filter, flatten, flapMap, drop, take, zip, ... Learn the concepts in…

I program mainly in C++, and I often start off writing things as: for (auto x : someContainer) { //do something with x } But inevitably, I end up needing either an iterator pointing to a particular item at the end, or I need an index to pass to some other function, and this style makes that impossible. Perhaps it's just the domain I work in, but even after years of trying to make this work, it still only works about…

In Haskell

   map someFunction listOfValue
if you need an index:

   map someOtherFunction (zip [0..] listOfValues)
Python uses 'enumerate' to similar effect. Not sure if C++ has an equivalent?

Re: The general value of typed functional programming lies in leaving no edge cases

#70
post #63
post #44

I am not sure this is the only value, but it is generally true. And this is one of the great advantages of haskell. By the way, now that I know some haskell, I see this edge case sloppiness all the time and it is really annoying. For example, here is something that annoyed me just recently. You go to yahoo finance and there they will show you the revenues of a company as well as the revenue growth from past year. But…

Ive noticed other languages with this feature, they call them optional types, you can pass in a null or a type value. /s slightly, maybe more snarky, but seriously, optional types are way overhyped. Null objects are far more useful than optionals. Optionals tend to leak all over the show.

I don't understand. In this situation an optional type is a reasonable solution to the problem: None => N/A, Some(0%) => 0%.
Post reply on HN