flix / flix

The Flix Programming Language
https://flix.dev/
Other
2.15k stars 151 forks source link

Functor, Applicative, Monad implementations #2186

Closed felixwiemuth closed 1 year ago

felixwiemuth commented 3 years ago

This is an overview on the implementation status of the Functor, Applicative and Monad typeclasses.

Conventions for implementation, test and documentation

When implementing Applicative, I established some conventions (discussable of course):

Notes on some type classes

Applicative

Implementation

Datatype Functor Applicative Monad
Option :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
Result
List :heavy_check_mark: :heavy_check_mark: (E: ap, liftA2, T: liftX) :heavy_check_mark:
Nel :heavy_check_mark: :x: (:heavy_check_mark:)
Array :heavy_check_mark: :x:
MutList :heavy_check_mark: :x:
magnus-madsen commented 3 years ago

A general comment:

felixwiemuth commented 3 years ago

Okay. Good point with Result, I'll check the instances for it when I come to Monad.

mlutze commented 3 years ago

Result/Validation may not be possible at the moment. See https://github.com/flix/flix/issues/1535

stephentetley commented 3 years ago

Is the pragmatic path to change the order of the type params for Validation and Result?

There will be quite a bit of code breakage - but if they are left longer there would be more breakage (if changing the param order remains the solution).

In Haskell fun deps and type families are the (competing) ways of programming on the "non-last" type params for some situations but dropping the last param of objects like Result is the way to make them kind -> so they can work with Functor, Applicative, Monad.