Package

purescript-kancho

Repository
justinwoo/purescript-kancho
License
MIT
Uploaded by
justinwoo
Published on
2017-12-16T12:15:37Z

A helper library for constraining types to be Elm port-safe and for providing helpers to codegen Elm types.

Named for a nice Korean snack Kancho that wraps a chocolate core with biscuit.

(Or for the Japanese prank of poking people in their butthole)

tl;dr

newtype Coords = Coords
  { x :: Int
  , y :: Int
  }
derive instance newtypeCoords :: Newtype Coords _
instance hasElmPortVersionCoords :: HasElmPortVersion Coords where
  toElmTypeRep _ = "Coords"

type EtchSketch =
  { cursor :: Coords
  , points :: Array Coords
  }

outputs

type alias Coords =
    { x : Int
    , y : Int
    }


type alias EtchSketch =
    { cursor : Coords
    , points : List Coords
    }

Example

The tests provide some examples to follow along with.

Example Usage/Motivations

The major chunk of this library is from work done for my Elm-in-Halogen integration demo -- specifically on the row-to-list-ver branch. The demo repo generates Elm types to a file and runs the Elm compiler in the full build, and uses port-safe types.

A blog post about the Generics-Rep version is available here, but this library uses the newer RowToList 0.11.6 feature as a simpler way to constrain types.