• Stars
    star
    101
  • Rank 326,766 (Top 7 %)
  • Language
    Elm
  • License
    BSD 3-Clause "New...
  • Created over 8 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Haskell: Derive Elm types from Haskell types

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!

This version of the package only supports Elm 0.19. Version 0.5.2 supports Elm 0.18, and Version 0.3.0.2 supports Elm 0.16 and Elm 0.17.

Note that the bartavelle/json-helpers package, with version >= 1.2.0, is expected by the generated Elm modules.

Usage

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

import Data.Proxy

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

deriveBoth defaultOptions ''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
import Json.Helpers exposing (..)


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

jsonDecFoo : Json.Decode.Decoder ( Foo )
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 : Foo -> Value
jsonEncFoo  val =
   Json.Encode.object
   [ ("f_name", Json.Encode.string val.f_name)
   , ("f_blablub", Json.Encode.int val.f_blablub)
   ]

Also, there are functions Elm.Json.stringSerForSimpleAdt and Elm.Json.stringParserForSimpleAdt to generate functions for your non-JSON ADT types.

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

Install

Haskell

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

Elm

  • elm package install bartavelle/json-helpers

or, for Elm 0.19:

  • elm install bartavelle/json-helpers

Contribute

Pull requests are welcome! Please consider creating an issue beforehand, so we can discuss what you would like to do. Code should be written in a consistent style throughout the project. Avoid whitespace that is sensible to conflicts. (E.g. alignment of = signs in functions definitions) Note that by sending a pull request you agree that your contribution can be released under the BSD3 License as part of the elm-bridge package or related packages.

More Repositories

1

Spock

Another Haskell web framework for rapid development
Haskell
676
star
2

rubyspeed

Compile ruby functions to C
Ruby
183
star
3

funblog

A simple blog software written in Haskell
Haskell
84
star
4

superrecord

Haskell: Supercharged anonymous records
Haskell
83
star
5

users

A library simplifying user management for Haskell web applications
Haskell
51
star
6

openai-hs

Unofficial OpenAI Haskell Bindings
Haskell
46
star
7

WebSocketServer

C++ WebSocketServer implementation with LUA integration
C++
38
star
8

elm-react

React bindings for Elm
JavaScript
25
star
9

superbuffer

Haskell: Efficiently build a bytestring from smaller chunks
Haskell
24
star
10

purescript-apparch

PureScript application layout pattern, derived from the Elm Architecture
PureScript
18
star
11

react-flux-example

Haskell: Overengineered GHCJS + react-flux playground
Haskell
14
star
12

hackmanager

Simplify managing Haskell projects by generating files like README.md, .travis.yml, etc.
Haskell
12
star
13

highjson

Haskell: Low boilerplate, easy to use and very fast Haskell JSON serialisation and parsing
Haskell
11
star
14

superevent

Haskell: A simple opinionated event store implementation
Haskell
10
star
15

hvect

Haskell: Simple heterogeneous lists
Haskell
10
star
16

Spock-scotty-benchmark

Haskell: Spock vs scotty benchmark
Haskell
10
star
17

simple-logger

Haskell: A very simple but efficient logging framework
Haskell
9
star
18

reroute

Haskell: abstract implementation of typed and untyped web routing
9
star
19

scotty-session

Adding session functionality to scotty
Haskell
8
star
20

validate-input

A small Haskell combinator library that provides a simple way of validating user provided data structures
Haskell
8
star
21

powerqueue

Haskell: A flexible job queue with exchangeable backends
Haskell
7
star
22

haskell-smtp-server

Simple SMTP Server in Haskell
Haskell
6
star
23

elm-bootforms

Quickly create forms using bootstrap and elm
Elm
6
star
24

Spock-digestive

Digestive functors support for Haskell Web-Framework Spock
Haskell
6
star
25

micro-lisp

Haskell: a small lisp interpreter
Haskell
6
star
26

legoDSL

Haskell LegoDSL
Haskell
5
star
27

timespan

Haskell: library for timespans
Haskell
5
star
28

Spock-worker

Background workers for Spock
Haskell
5
star
29

stripe-hs

Unofficial (and Incomplete) Stripe Haskell Bindings
Haskell
5
star
30

grabcite

Haskell: Library/Executable to extract citations from scientific papers
TeX
5
star
31

pulse

Haskell: Synchronize multiple actions to be triggered as parallel as possible
Haskell
4
star
32

ghc-docker

Ubuntu based docker images running GHC
Shell
4
star
33

revenue-sample-app

Example Spock Project for f(by)
Haskell
4
star
34

ghcjs-ajax

Haskell: Cross browser AJAX Bindings for GHCJS
Haskell
4
star
35

format-numbers

Haskell: Various number formatting functions
Haskell
4
star
36

ai-planning

Basic AI planning algorithms
Haskell
4
star
37

flightmonitor

Haskell: A tool to monitor flight prices given a trip specification
Haskell
4
star
38

HSmarty

Haskell implementation of a subset of the PHP-Smarty template language
Haskell
4
star
39

aws-simple

Haskell: Simple bindings to commonly used AWS Services
Haskell
3
star
40

language-ruby

Haskell: a ruby language toolkit
Haskell
3
star
41

hasql-simple

Haskell: A somewhat opinionated "simpler" API to hasql
Haskell
3
star
42

hackageship

Automatically ship Haskell packages to Hackage on Github releases
Go
3
star
43

blaze-bootstrap

Haskell: Simplify building blaze and bootstrap powered pages
Haskell
3
star
44

yahoo-finance-conduit

Small haskell library streaming stock market data from the yahoo finance api
Haskell
3
star
45

apparch-example

Example project for purescript-apparch
PureScript
3
star
46

vector-simd

Haskell: Vector operations explicitly implemented with SIMD (experimental)
Haskell
3
star
47

ignore

Library and tiny tool for working with ignore files of different version control systems
Haskell
2
star
48

dataurl

Haskell: Handle data-urls
Haskell
2
star
49

reproject

Haskell: Define and combine "materialized" projections
Haskell
2
star
50

Spock-bench

Spock benchmarks
Haskell
2
star
51

async-extra

Haskell: Various concurrent combinators
Haskell
2
star
52

distance

Haskell: Useful distance datatype and functions
Haskell
2
star
53

free-stream

Haskell: A simple streaming library built on free monads
Haskell
2
star
54

batch

Haskell: Simplify queuing up data and processing it in batch.
Haskell
2
star
55

SimplePHPCouch

A very simple PHP wrapper for the CouchDB REST API
PHP
2
star
56

hocker

Haskell: Docker client
Haskell
2
star
57

tile-cutter

Haskell: utility to cut a large image into smaller tiles
Haskell
2
star
58

Spock-auth

Provides authentification helpers for Spock
Haskell
2
star
59

haskell-playground

Just a collection of small haskell tools/programs
Haskell
2
star
60

fileplow

Haskell: Library to process and search large files or a collection of files
Haskell
2
star
61

parser-playground

Haskell: small parser combinator library
Haskell
2
star
62

grabcite-net

Neural Network for citation recommendation
Python
2
star
63

digestive-bootstrap

Haskell: Speed up form designing using digestive functors and bootstrap
Haskell
2
star
64

recordscript

A fast language that compiles to JS
Haskell
2
star
65

meme-tutorial

Haskell: Material for Sommercampus 2017 Freiburg
Haskell
1
star
66

bluemix-sdk

Haskell: Bindings to IBM Bluemix/Watson APIs
Haskell
1
star
67

psql-helpers

Haskell: A small collection of helper functions to generate postgresql queries
Haskell
1
star
68

B0rbit

(outdated) python bot for http://darkorbit.de
Python
1
star
69

papergrep

Haskell: Hassle free search API for DBLP
Haskell
1
star
70

text-utils

Haskell: Library with useful text utility functionality
Haskell
1
star
71

FastAGI

Haskell Framework for creating FastAGI Servers
Haskell
1
star
72

Spock-rest

DSL for defining RESTful services in Spock (WIP)
Haskell
1
star
73

flow-sequence

JavaScript: Efficient chaining of operations of array like structures
JavaScript
1
star
74

api-enforcer

Haskell: Library and tool to test APIs
Haskell
1
star
75

farbton

TypeScript: small daemon to control my Hue lights
TypeScript
1
star
76

superrocks

Haskell: A high level interface to RocksDB
Haskell
1
star
77

dsconnect

Social Network for TribalWars
PHP
1
star
78

DKBot

Python: Bot for die-kreuzzuege.de
Python
1
star
79

purescript-preface

An alternative to the Prelude for teaching purposes
PureScript
1
star
80

Spock-starter

Haskell: A Spock starter kit for MuniHac2016 web programming workshop
Haskell
1
star
81

filewatch

Haskell: Observe a file for changes and automatically load it
Haskell
1
star
82

managerslife

A MMORPG Browsergame
PHP
1
star