在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):agrafix/elm-bridge开源软件地址(OpenSource Url):https://github.com/agrafix/elm-bridge开源编程语言(OpenSource Language):Elm 60.6%开源软件介绍(OpenSource Introduction):Elm BridgeIntroHackage: 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 For more usage examples check the tests or the examples dir. InstallHaskell
Elm
or, for Elm 0.19:
ContributePull 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 |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论