elm-bridge: Derive Elm types from Haskell types

[ bsd3, compiler, language, library, web ] [ Propose Tags ]

Building the bridge from Haskell to Elm and back. Define types once, use on both sides and enjoy easy (de)serialisation. Cheers!


[Skip to Readme]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.2.1.0, 0.2.1.1, 0.2.2.0, 0.2.2.1, 0.3.0.0, 0.3.0.2, 0.4.0, 0.4.1, 0.4.2, 0.4.3, 0.5.0, 0.5.1, 0.5.2, 0.6.0, 0.6.1, 0.7.0, 0.8.0, 0.8.1, 0.8.2, 0.8.3
Dependencies base (>=4.7 && <5), template-haskell [details]
License BSD-3-Clause
Copyright (c) 2015 Alexander Thiemann
Author Alexander Thiemann <mail@athiemann.net>
Maintainer Alexander Thiemann <mail@athiemann.net>
Revised Revision 1 made by AlexanderThiemann at 2015-08-10T09:56:23Z
Category Web, Compiler, Language
Home page http://github.com/agrafix/elm-bridge
Source repo head: git clone https://github.com/agrafix/elm-bridge
Uploaded by AlexanderThiemann at 2015-08-09T21:05:46Z
Distributions LTSHaskell:0.8.3, NixOS:0.8.3
Reverse Dependencies 2 direct, 0 indirect [details]
Downloads 11224 total (63 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2015-08-09 [all 1 reports]

Readme for elm-bridge-0.1.0.0

[back to package description]

Elm Bridge

Build Status

Hackage Deps

Intro

Hackage: elm-bridge

Building the bridge from Haskell to Elm and back. Define types once, use on both sides and enjoy easy (de)serialisation. Cheers!

Usage

{-# LANGUAGE TemplateHaskell #-}
import Elm.Derive
import Elm.Module

import Data.Proxy

data Foo
   = Foo
   { f_name :: String
   , f_blablub :: Int
   } deriving (Show, Eq)

deriveElmDef defaultOpts ''Foo

main :: IO ()
main =
    putStrLn $ makeElmModule "Foo"
    [ DefineElm (Proxy :: Proxy Foo)
    ]

Output will be:

module Foo where

import Json.Decode
import Json.Decode exposing ((:=))
import Json.Encode


type alias Foo  =
   { f_name: String
   , f_blablub: Int
   }

jsonDecFoo  =
   ("f_name" := Json.Decode.string) `Json.Decode.andThen` \pf_name ->
   ("f_blablub" := Json.Decode.int) `Json.Decode.andThen` \pf_blablub ->
   Json.Decode.succeed {f_name = pf_name, f_blablub = pf_blablub}

jsonEncFoo  val =
   Json.Encode.object
   [ ("f_name", Json.Encode.string val.f_name)
   , ("f_blablub", Json.Encode.int val.f_blablub)
   ]

For more usage examples check the tests or the examples dir.

Install

  • Using cabal: cabal install elm-bridge
  • From Source: git clone https://github.com/agrafix/elm-bridge.git && cd elm-bridge && cabal install