Package

purescript-kancho

Repository
justinwoo/purescript-kancho
License
MIT
Uploaded by
justinwoo

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

log <<< unsafeStringify $ toElmModel coords
  -- equivalent to JSON.stringify
  log <<< unsafeStringify $ toElmModel coords
  
  -- uses getElmRep to get the Elm type representation of Coords
  log $ "type Coords = " <> getElmRep (Proxy :: Proxy Coords)
  -- (Proxy lets us not have to provide a concrete value for Coords)

  where
    coords :: Coords
    coords = {x: 1, y: 2}

outputs

{"x":1,"y":2}

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

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.