Holmusk / elm-street

:deciduous_tree: Crossing the road between Haskell and Elm
Mozilla Public License 2.0
88 stars 6 forks source link

Divide (closed) Primitives and (opened) Builtins #119

Open turboMaCk opened 3 years ago

turboMaCk commented 3 years ago

Splitting ElmPrim into:

ElmPrim keeps its original closed design using variants in sum type.

ElmBuiltins is using record/product to make implementation open. This gives elm-street several new features:

Full vocabulary of ElmDefinition:

Example definitions

-- simple type instance
instance Elm Value where
    toElmDefinition _ = DefBuiltin $ ElmBuiltin
        { builtinImplType = "Value"
        , builtinImplEncoder = "Basics.identity"
        , builtinImplDecoder = "D.value"
        , builtinImplParams = []
        }

-- parametrized type instance
instance (Elm a, Elm b) => Elm (Either a b) where
    toElmDefinition _ = DefBuiltin $ ElmBuiltin
        { builtinImplType = "Result"
        , builtinImplEncoder = "elmStreetEncodeEither"
        , builtinImplDecoder = "elmStreetDecodeEither"
        , builtinImplParams = [elmRef @a, elmRef @b]
        }

Future work to be done

Possibly further extensions:

Related issues:

related closed issues:


@jhrcek This is not ready for merge but I figured it would be better to get your feedback as soon as I have working spike. Please feel free to comment. This PR resolves my single biggest frustration of working with elm-street.

@arbus I think you might also give input to this proposal