shwifty: Generate swift types from haskell types.

[ codegen, library, mit, templatehaskell, text ] [ Propose Tags ] [ Report a vulnerability ]

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]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.0.1.0, 0.0.2.0, 0.0.3.0
Change log CHANGELOG.md
Dependencies base (>=4.11 && <4.14), bytestring (>=0.10 && <0.11), case-insensitive (>=1.2 && <1.3), containers (>=0.5.9 && <0.7), mtl (>=2.2 && <2.3), primitive (>=0.6.4 && <0.8), template-haskell (>=2.11 && <2.17), text (>=1.2 && <1.3), th-abstraction (>=0.3 && <0.4), time (>=1.8 && <1.10), unordered-containers (>=0.2 && <0.3), uuid-types (>=1.0 && <1.1), vector (>=0.12 && <0.13) [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 2020-02-27T06:34:26Z
Distributions
Downloads 747 total (17 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2020-02-27 [all 1 reports]

Readme for shwifty-0.0.2.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>
}