Examples:
data SumType = Sum1 | Sum2 | Sum3
getShwifty ''SumType
enum SumType {
case sum1
case sum2
case sum3
}
data ProductType = ProductType { x :: Int, y :: Int }
getShwifty ''ProductType
struct ProductType {
let x: Int
let y: Int
}
data SumType a b = SumL a | SumR b
getShwifty ''SumType
enum SumType<A, B> {
case sumL(A)
case sumR(B)
}
data ProductType a b = ProductType
{ aField :: a
, bField :: b
}
getShwifty ''ProductType
struct ProductType<A, B> {
let aField: A
let bField: B
}
newtype Newtype a = Newtype { getNewtype :: a }
getShwifty ''Newtype
struct Newtype<A> {
let getNewtype: A
}
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?>
}
data PolyKinded (a :: k) = PolyKinded
getShwifty ''PolyKinded
struct PolyKinded<A> { }
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)
}
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>
}