Introducing elm-typed

I have built a package named elm-typed which is well inspiared by Punie/elm-id and joneshf/elm-tagged.

This packages internally uses phantom type that “tags” primitive types in your application to be identified in compile-time.

Tagging is a common feature as both elm-id and elm-tagged also have, but the unique feature this package has is permission (ReadWrite and ReadOnly in the example below) which enables users to statically control modifiability of tagged values. With permission, users can use this package to tag both stational, fixed values (eg. ID) and variable values (eg. Input form). This is type-level protection of unintentional modification.

Quick Examples

import Typed exposing (Typed, ReadOnly, ReadWrite)


type MemberIdType
    = MemberIdType

type alias MemberId
    = Typed MemberIdType String ReadOnly

type AgeType
    = AgeType

type alias Age
    = Typed AgeType Int ReadWrite

type alias Model =
    { memberId : MemberId
    , age : Age
    }

memberId will not be able to be reassign anymore in this example, because it is marked as ReadOnly at its definition.

newMemberId : MemberId
newMemberId =
    Typed.new "1" -- compile error!

newAge : Age
newAge =
    Typed.new 30 -- ok

More details are on README.

Hope this package help your Elm application be more maintainable.

11 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.