Giter VIP home page Giter VIP logo

Comments (7)

gusty avatar gusty commented on May 22, 2024

Interesting.

The idea is that option are containers, something like a list that can be either empty or with only one element (actually that was the way I emulated options 15 years ago in other languages).

So why does it works here?

It works because Option is a Foldable, which supports the operation toSeq and that's used in the default implementation of length. This function will return either 0 or 1 when applied to options.

We can certainly change that behavior, but to me looks good in principle, unless you have a good reason to remove it.

Sometime ago there was a suggestion in the F# user voice to make Option<'T> implement IEnumerable<'T> which was declined for technical limitation.
If it wasn't for that technical limitation you would be able without this library to do Seq.length None = 0.

from fsharpplus.

robkuz avatar robkuz commented on May 22, 2024

No need to change that. It was only surprising (not knowing that).
effectively I had a Option<Option<string>> and a Option<string> which I both piped thru the same generic code. At a later code I was checking the len of the inner value and was surprised that it was always 0 when in effect I was (unconciously) expecting a compiler error.

maybe this should be document

from fsharpplus.

gusty avatar gusty commented on May 22, 2024

Actually, on my free time, I'm working on documenting the library.
Have a look at the abstractions here for example.
I still need to add the page for Foldable, but you will see as in the others, all methods and all types that are supported.
Although it's a lot of work, but it's something that needs to be done, given the size this library is getting, in terms of features and abstractions.

PS: I think in other languages/libraries (Haskell, Purescript, Idris, Scalaz) it's also a Foldable.

from fsharpplus.

robkuz avatar robkuz commented on May 22, 2024

Hey that looks sweet!
Can we have some samples for each of those. I am willing to help on this.

from fsharpplus.

mausch avatar mausch commented on May 22, 2024

There was quite a bit of criticism and confusion in the Haskell community around this when they were discussing whether to make Foldable part of the Prelude, notably around tuples. https://mail.haskell.org/pipermail/libraries/2016-February/026805.html

Personally I think it's fine.

from fsharpplus.

gusty avatar gusty commented on May 22, 2024

@mausch Interesting discussion. Here's foldable in purescript, they have lot of interesting instances we still don't. I think is a good source of inspiration since it's relatively new and they don't have the "breaking change problem", like Haskell libraries.

from fsharpplus.

gusty avatar gusty commented on May 22, 2024

@robkuz It would be really, really nice to have some samples either linked or at the foot of each abstraction page.

I just updated the docs to the latest version I have. If you want to add more stuff or samples, please do it. If you have questions about how to add things to the docs, please open an Issue with the questions and I will help.

Thanks in advance.

from fsharpplus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.