shwifty: Generate swift types from haskell types.

[ codegen, library, mit, templatehaskell, text ] [ Propose Tags ]

Shwifty provides many utilities for generating swift types from haskell types, with great flexibility in representation, and emphasis on generating typesafe Swift code. Most of the types representable in Haskell98 are supported.


[Skip to Readme]
Versions [faq] 0.0.1.0
Change log CHANGELOG.md
Dependencies base (>=4.11 && <4.14), bytestring (==0.10.*), case-insensitive (==1.2.*), containers (>=0.5.9 && <0.7), mtl (==2.2.*), primitive (==0.7.*), template-haskell (>=2.11 && <2.17), text (==1.2.*), th-abstraction (==0.3.*), time (>=1.8 && <1.10), unordered-containers (==0.2.*), uuid-types (==1.0.*), vector (==0.12.*) [details]
License MIT
Copyright Copyright (c) 2020, chessai
Author chessai
Maintainer chessai <chessai1996@gmail.com>
Category Codegen, Text, TemplateHaskell
Bug tracker https://github.com/chessai/shwifty/issues
Source repo head: git clone git://github.com/chessai/shwifty.git
Uploaded by chessai at Tue Feb 4 01:07:45 UTC 2020
Distributions
Downloads 40 total (40 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2020-02-04 [all 1 reports]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for shwifty-0.0.1.0

[back to package description]

Shwifty

Generate Swift types from Haskell types

Examples:

A simple sum type

data SumType = Sum1 | Sum2 | Sum3
getShwifty ''SumType
enum SumType {
    case sum1
    case sum2
    case sum3
}

A simple product type

data ProductType = ProductType { x :: Int, y :: Int }
getShwifty ''ProductType
struct ProductType {
    let x: Int
    let y: Int
}

A sum type with type variables

data SumType a b = SumL a | SumR b
getShwifty ''SumType
enum SumType<A, B> {
    case sumL(A)
    case sumR(B)
}

A product type with type variables

data ProductType a b = ProductType 
  { aField :: a
  , bField :: b 
  }
getShwifty ''ProductType
struct ProductType<A, B> {
    let aField: A
    let bField: B
}

A newtype

newtype Newtype a = Newtype { getNewtype :: a }
getShwifty ''Newtype
struct Newtype<A> {
    let getNewtype: A
}

A type with a function field

newtype Endo a = Endo { appEndo :: a -> a }
getShwifty ''Endo
struct Endo<A> {
    let appEndo: ((A) -> A)
}

A weird type with nested fields. Also note the Result's types being flipped from that of the Either.

data YouveGotProblems a b = YouveGotProblems 
  { field1 :: Maybe (Maybe (Maybe a))
  , field2 :: Either (Maybe a) (Maybe b) 
  }
getShwifty ''YouveGotProblems
struct YouveGotProblems<A, B> {
    let field1: A???
    let field2: Result<B?, A?>
}

A type with polykinded type variables

data PolyKinded (a :: k) = PolyKinded
getShwifty ''PolyKinded
struct PolyKinded<A> { }

A sum type where constructors might be records

data SumType a b (c :: k) 
  = Sum1 Int a (Maybe b) 
  | Sum2 b 
  | Sum3 { x :: Int, y :: Int }
getShwifty ''SumType
enum SumType<A, B, C> {
  case field1(Int, A, B?)
  case field2(B)
  case field3(_ x: Int, _ y: Int)
}

A type containing another type with instance generated by 'getShwifty'

newtype MyFirstType a = MyFirstType { getMyFirstType :: a }
getShwifty ''MyFirstType

data Contains a = Contains 
  { x :: MyFirstType Int
  , y :: MyFirstType a 
  }
getShwifty ''Contains
struct MyFirstType<A> {
  let getMyFirstType: A
}

struct Contains<A> {
  let x: MyFirstType<Int>
  let y: MyFirstType<A>
}