question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: specs for Maybe, Either, Tuple, Task, ...

See original GitHub issue

Sorry if it was discussed before, after scanning the issues I didn’t find anything on the subject.

The motivation comes from the last addition: the spec for chainRec which I find hard to understand

chainRec :: ChainRec m => ((a -> c, b -> c, a) -> m c, a) -> m b

with respect to

class Monad m <= MonadRec m where
  tailRecM :: forall a b. (a -> m (Either a b)) -> a -> m b

Relevant issues

I understand the benefits of not depending on a particular implementation of Either but why fantasy-land doesn’t provide a spec for Either in the first place?

For example writing the spec for Unfoldable would be problematic (Maybe AND Tuple)

class Unfoldable t where
  unfoldr :: forall a b. (b -> Maybe (Tuple a b)) -> b -> t a

We have great libraries out there for Maybe, Either, Task, etc… but there’s no standard for them.

Would it be a good idea to add specs for these concrete types?

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:61 (46 by maintainers)

github_iconTop GitHub Comments

5reactions
puffnfreshcommented, Oct 21, 2016

@gcanti those data-types can be Church-encoded (pedantically, Boehm-Berarducci encoded, if we’re using types) meaning they can be represented as functions.

type Maybe a = forall b. b -> (a -> b) -> b
type Either a b = forall c. (a -> c) -> (b -> c) -> c
function nothing(b, f) {
  return b;
}

function just(a) {
  return function(b, f) {
    return f(a);
  };
}

function left(a) {
  return function(l, r) {
    return l(a);
  };
}

function right(b) {
  return function(l, r) {
    return r(b);
  };
}

// Example
function eitherToMaybe(e) {
  return e(
    function(ignored) { return nothing; },
    just
  );
}
4reactions
gabejohnsoncommented, Jan 19, 2018

@robotlolita I’ve made some changes to #280 that would make interop very simple.

That being said, I think any specification is better than none.

we should just implement the data structures in Fantasy Land, we could even have a fantasy-land-runtime library that provides operations on those values

Agreed. In fact, why have more than one ADT library? Currently we have:

And these are just the libraries in the Fantasy Land ecosystem. There seems to be a lot of duplicated effort.

@robotlolita a simple spec, as you mentioned above, could be implemented once using daggy (with contributions from all interested lib authors/maintainers).

I’ve noticed a lot of confusion amongst those new to FL concerning where they should get their data types. It creates an unnecessary barrier to entry for beginners and hurts the ecosystem as a whole.

I’m not saying every data type should come from this org, but the basic ones are so simple there’s no good reason to do so repeatedly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Proposal: Language support for Tuples #347 - GitHub
As mentioned, I propose to make tuple types structs rather than classes, so that no allocation penalty is associated with them. They should...
Read more >
Write Pythonic and Clean Code With namedtuple - Real Python
Use namedtuple instances to write Pythonic code; Decide whether to use a namedtuple or a similar data structure; Subclass a namedtuple to provide...
Read more >
PEP 622 – Structural Pattern Matching
We propose that destructuring objects can be customized by a new special __match_args__ attribute. As part of this PEP we specify the general...
Read more >
Nullable reference types - C# 9.0 specification proposals
Every expression in a given source location has a null state, which indicated whether it is believed to potentially evaluate to null. The...
Read more >
Automated replication of tuple spaces via static analysis
Coordination languages for tuple spaces can offer significant ... can be either local or remote, in the sense that they can be possibly...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found