elm-bridge

Derive Elm types from Haskell types

http://github.com/agrafix/elm-bridge

Version on this page:0.1.0.0@rev:1
LTS Haskell 22.21:0.8.3
Stackage Nightly 2023-12-26:0.8.2
Latest on Hackage:0.8.3

See all snapshots elm-bridge appears in

BSD-3-Clause licensed and maintained by Alexander Thiemann
This version can be pinned in stack with:elm-bridge-0.1.0.0@sha256:705fd50300a9611e7be3908004980f1a82589bd82e1ea2f9bf1ec67396e86ca1,1714

Module documentation for 0.1.0.0

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