Skip to content

Instantly share code, notes, and snippets.

Avatar

Jeroen Engels jfmengels

View GitHub Profile
@jfmengels
jfmengels / Differences between elm-review.md
Last active Jul 30, 2020
Differences between elm-review and ESLint
View Differences between elm-review.md
@jfmengels
jfmengels / NoMissingVariants.elm
Last active Jun 11, 2020
NoMissingVariants rule
View NoMissingVariants.elm
module NoMissingVariants exposing (rule)
import Dict exposing (Dict)
import Elm.Syntax.Declaration as Declaration exposing (Declaration)
import Elm.Syntax.Expression as Expression exposing (Expression)
import Elm.Syntax.Node as Node exposing (Node)
import Elm.Syntax.Type exposing (Type)
import Elm.Syntax.TypeAnnotation as TypeAnnotation exposing (TypeAnnotation)
import Review.Rule as Rule exposing (Error, Rule)
import Set exposing (Set)
@jfmengels
jfmengels / problem.md
Last active Apr 12, 2020
API design puzzle - The car factory
View problem.md

Imagine you try to design "factories". You have factories that can build Diesel cars, and factories that can build any kind of car (Diesel and Gas, but other kinds of cars could exist). Let's say you want the user to be able to create their customized car factory, for which you provide an API, like

I have a module Factory which defines a Factory and a Car type, all opaque. I provide two functions createCarFactory and createDieselCarFactory, where the first one takes a use-provided function that can return a list of any cars (and they can be mixed), and the second one can only generate Diesel cars.

I want the garantee as the module author, that users won't be able to provide functions that create cars other than diesel cars in the createDieselCarFactory, while still allowing to create any kind of car with the createCarFactory function.

I want the type system to be the one to complain if these guarantees are not respected by the user.

View NoMissingTypeConstructor.elm
module NoMissingTypeConstructor exposing (rule)
import Dict exposing (Dict)
import Elm.Syntax.Declaration as Declaration exposing (Declaration)
import Elm.Syntax.Expression as Expression exposing (Expression)
import Elm.Syntax.Node as Node exposing (Node)
import Elm.Syntax.Type exposing (Type)
import Elm.Syntax.TypeAnnotation as TypeAnnotation exposing (TypeAnnotation)
import Review.Rule as Rule exposing (Error, Rule)
import Set exposing (Set)
You can’t perform that action at this time.