• Stars
    star
    116
  • Rank 303,894 (Top 6 %)
  • Language
    Haskell
  • License
    Eclipse Public Li...
  • Created about 9 years ago
  • Updated 10 months ago

Reviews

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

Repository Details

Create Elm types and JSON decoders from Haskell source.

Elm Export

Build Status

Create Elm classes and JSON decoders from Haskell DataTypes.

Installation

Elm Export is available on Hackage.

Usage

To use this library, you must first make the types you want to export implement ElmType. This is easy. Just derive Generic, and then we can automatically generate the ElmType instance for you. Here's an example with a Person type:

{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-}

module Db where

import Elm
import GHC.Generics

data Person = Person
  { id :: Int
  , name :: Maybe String
  } deriving (Show, Eq, Generic, ElmType)

That's it for the type. Now you'll want to write a main that generates the Elm source code:

module Main where

import Data.Proxy
import Db
import Elm

spec :: Spec
spec =
  Spec
    ["Db", "Types"]
    [ "import Json.Decode exposing (..)"
    , "import Json.Decode.Pipeline exposing (..)"
    , toElmTypeSource (Proxy :: Proxy Person)
    , toElmDecoderSource (Proxy :: Proxy Person)
    ]

main :: IO ()
main = specsToDir [spec] "some/where/output"

Run this and the directory some/where/output will be created, and under that the Elm source file Db/Types.elm will be found.

All the hard work here is done by toElmTypeSource and toElmDecoderSource. The Spec code is just wrapping to make it easy to create a complete Elm file from the meat that ElmType gives you.

Required Elm Packages

The decoders we produce require these extra Elm packages installed:

elm package install NoRedInk/elm-decode-pipeline
elm package install krisajenkins/elm-exts

Development

You will need Stack.

Building

stack build

Testing

stack test --file-watch

Change Log

V0.3.0.0

  • Renamed ToElmType to ElmType, for brevity.

V0.2.0.0

V0.1.0.0

  • Initial release.

Status

Alpha. The author is using it in production, but it is not yet expected to work for every reasonable case.

There are some Haskell datatypes that cannot be represented in Elm. Obviously we will not support those. But there are some which are legal Haskell and legal Elm, but we do not yet generate. Please send examples, PRs and code-suggestions!

Contributors

License

Copyright © 2015-2017 Kris Jenkins

Distributed under the Eclipse Public License.

See Also

Elm Bridge is a different implementation of the same goal. That project uses Template Haskell, this one uses GHC Generics.

More Repositories

1

yesql

A Clojure library for using SQL.
Clojure
1,462
star
2

remotedata

Tools for fetching data from remote sources (incl. HTTP).
Elm
253
star
3

vim-pipe

Send a vim buffer through a command and instantly see the output.
Vim Script
184
star
4

helm-spotify

A simple Spotify-for-Emacs interface.
Emacs Lisp
180
star
5

petrol

A simple event-handling framework for ClojureScript projects.
Clojure
127
star
6

elm-dialog

A modal library for Elm
Elm
91
star
7

evil-tabs

Integrating Vim-style tabs for Evil mode users.
Emacs Lisp
66
star
8

ob-browser

Render HTML inside Emacs' org-mode
Emacs Lisp
57
star
9

elm-exts

A toolkit of useful extensions to the core Elm libraries.
Elm
50
star
10

ob-translate

Allows you to translate blocks of text within org-mode.
Emacs Lisp
47
star
11

vim-projectlocal

Per-project .vimrc files.
Vim Script
40
star
12

formatting

A type-safe string formatting library. printf: elm style.
Elm
38
star
13

ob-mongo

Execute mongodb queries within org-mode blocks.
Emacs Lisp
36
star
14

EvilBegins

Vim user? Emacs curious? Try this...
Emacs Lisp
35
star
15

purescript-remotedata

PureScript
34
star
16

autoheadline

Generate Headlines from Hacker News
Elm
33
star
17

Cloud-Haskell-Game

A hackers' game server, written in Cloud Haskell.
Haskell
30
star
18

TrollDB

An in-memory JavaScript database that prioritises performance over everything.
JavaScript
29
star
19

AdventOfCode

PureScript solutions for Advent of Code
PureScript
16
star
20

elm-astar

The A* pathfinding algorithm for Elm.
Elm
15
star
21

wispjs-mode

An Emacs major mode for Wisp - the Lisp -> JavaScript compiler.
Emacs Lisp
13
star
22

vim-postgresql-syntax

Syntax highlighing for the output of psql.
Vim Script
12
star
23

beeline-demo

A GeoHackDay hack of the BeeLine product
Elm
11
star
24

original-lisp

The Original LISP Interpreter In Clojure
Clojure
10
star
25

vim-and-sql

Tips & Tricks for Editing SQL with Vim
Vim Script
10
star
26

purescript-formatting

A type-safe, composable, printf-alternative for PureScript.
PureScript
10
star
27

the-prize

A Game
Elm
9
star
28

BellRinger

An experiment in porting my preferred ClojureScript architecture to Haskell
Haskell
9
star
29

lunarlander

Lunar Lander, In Elm, in 90 Minutes
Elm
8
star
30

LogicPuzzles

Using Clojure's core.logic to solve a logic puzzle.
Clojure
8
star
31

langtons-ant-elm

Elm
8
star
32

bare-bones-vim

Vim London 30/4/13 Presentation
Vim Script
7
star
33

SuperBomberElf

A Mildly Multiplayer Online Blowing People Up (MMOBPU) game.
Haskell
7
star
34

hack-voting

A voting tool for hack nights.
Elm
6
star
35

Haskell-Space-Trader

90 minutes worth of Haskell hacking to create an Elite clone.
Haskell
5
star
36

elm-from-scratch

Elm
5
star
37

vim-java-sql

A very simple plugin to enable SQL syntax highlighting inside strings in a Java file.
Vim Script
4
star
38

transcodegame

A game!
Elm
4
star
39

elm-cdn

Provides quick, convenient access to the frameworks you want to grab from a CDN.
Elm
4
star
40

huffman

Huffman Encoding in Haskell
Haskell
3
star
41

wireworld

The WireWorld Cellular Automata, in Elm
Elm
3
star
42

snaplet-auth

A Snap authentication snaplet (that uses JWT instead of sessions).
Haskell
3
star
43

regexfsm

PureScript
3
star
44

Tomorrows_JavaScript_Today

PureScript
3
star
45

infinite-runner

A 90 Minute Infinite-Runner hack
Elm
3
star
46

purescript-astar

PureScript
2
star
47

maze

A Clojure Maze Generator
Clojure
2
star
48

HackerGossip

August 2015's West London Hack Night Hack
Haskell
2
star
49

snap-postgresql

Simple snaplet for Postgres
Haskell
2
star
50

compose-elm

Elm
2
star
51

lispyscript-mode

An Emacs major mode for LispyScript
Emacs Lisp
2
star
52

cascalog-demo

Playing with an idea - Hadoop to D3 via Clojure & ClojureScript
JavaScript
2
star
53

cexl

A Lisp For Clojure Exchange 2013
JavaScript
2
star
54

CLJS-Demo

Hackernews Headlines With ClojureScript
Clojure
2
star
55

markov

Markov Chains in Haskell
Haskell
2
star
56

clojurescript-from-scratch

Presentation : Getting started with ClojureScript
2
star
57

elm-build

A build tool for full Elm projects
Haskell
2
star
58

ex-spotify

Sketchbook for the course A Crash Course In Clojure
Clojure
2
star
59

formatting-types

Type level string formatting library
Haskell
2
star
60

types-all-the-way-down

Presentation - Types All The Way Down
2
star
61

Kafka_202

Kafka Beyond The Basics
TypeScript
2
star
62

space-invaders

Elm
2
star
63

kashmir

Haskell
2
star
64

history

Manage History URIs in Elm
Elm
2
star
65

export-elm

Utilities for generating Elm code from Haskell.
Haskell
2
star
66

django-urlhelper

A simple manage.py command to make it easy to query Django's URL dispatcher
Python
2
star
67

Alice-in-Markov-Chains

The January 2014 West London Hack Night Clojure Hack
Clojure
2
star
68

Slack-Echo-Bot

A basic realtime slack bot, written in Haskell
Haskell
2
star
69

ClojureScriptForScale

ClojureX 2015 Presentation
CSS
1
star
70

diamondkata

The Diamond Kata in Elm
Elm
1
star
71

elm-for-real-work

An Elm Presentation
1
star
72

anagrams

Anagrams in Haskell - West London Hack Night - April 2015
Haskell
1
star
73

grid20

Grid 20 - An interview puzzle
Haskell
1
star
74

flatland

Discount CAD
Haskell
1
star
75

logo-purescript

A PureScript free monad hack of the Logo programming languages.
PureScript
1
star
76

flowchart

Elm experiment
Elm
1
star
77

gitparse

Haskell
1
star
78

ex-web

A Crash Course In Clojure Web Project
Clojure
1
star
79

game-of-life-rust

Conway's Game of Life, In ASCII, in Rust
Nix
1
star
80

AdventOfCodeHaskell

Haskell
1
star
81

tetris

West London Hack Night - Now much Tetris in 90 minutes?
Haskell
1
star
82

elm-maze

An Elm Maze Generator
Elm
1
star
83

langtonsant

Langton's Ant, in Clojure & Quil
Clojure
1
star
84

stack365

Replicating stack issue 365
Haskell
1
star
85

knapsack-haskell

The Knapsack Problem in Haskell
Haskell
1
star
86

shen-hacks

Playing around with Shen at West London Hack Night's "Hacking Blind"
1
star
87

vim-clojure-sql

A very simple plugin to enable SQL syntax highlighting inside strings in a Clojure file.
Vim Script
1
star
88

AStar

The A* Algorithm, In JavaScript, for a West London Hack Night.
JavaScript
1
star
89

status-dashboard

Nix
1
star
90

vim-jslint

Run :make on a JavaScript file, get JSLint messages in the quickfix buffer.
Vim Script
1
star
91

hack-malawi

A quick hack, visualizing some Malawi Aid Data
JavaScript
1
star
92

logic-jigsaw

Haskell
1
star