Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- enum
- type Day with
- case Saturday
- case Sunday
- case Meh
- end
- -- struct
- type User with
- field uid:i64
- field name:string
- field language:LangCode
- end
- -- generic struct
- type Point2D[T] with
- field x y:T
- end
- -- sum type
- type HttpResponse with
- case Timeout
- case OK(body:string)
- case NotFound
- case Redirect(url:string)
- end
- -- nested type
- type HttpResponse with
- case Response(code:i32) with
- case Success with
- case OK
- case Created
- case Accepted
- end
- case Redirection(url:string) with
- case Permanent
- case Temporary
- end
- case ClientError
- case BadRequest
- case NotFound
- case Forbidden
- end
- case ServerError
- case Internal
- case BadGateway
- end
- field headers:List[{string,string}]
- field body:string
- end
- case NetworkError(os_code:string)
- case Timeout
- end
- -- working with HttpResponse
- function foo(r:HttpResponse)
- match r with
- case Success as r then
- print(r.body)
- case Redirection(url) then
- foo(make_request(url))
- case Response(code) then
- print("Bad response")
- case Timeout then
- print("Timeout")
- case NetworkError(err) then
- print("Network error: ", err)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement