Skip to content
Create Elm types and JSON decoders from Haskell source.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
src #29: fix toElmTypeRef for tuples, add tests Jan 31, 2017
test Removing redundant brackets. Jan 31, 2017
.travis.yml Simplifying the travis config - it doesn't override the resolver. Feb 2, 2016
LICENSE.txt Initial release. Nov 10, 2015
Setup.hs Initial release. Nov 10, 2015
elm-export.cabal Version Jan 31, 2017
stack.yaml Changing the PVP bounds to only fix the lower end. Jan 17, 2017

Elm Export

Build Status

Create Elm classes and JSON decoders from Haskell DataTypes.


Elm Export is available on Hackage.


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 =
    ["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


You will need Stack.


stack build


stack test --file-watch

Change Log


  • Renamed ToElmType to ElmType, for brevity.



  • Initial release.


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!



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.

You can’t perform that action at this time.