Advertisement
mwchase

Sample sum_type code

Jun 5th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. R = typing.TypeVar('R')
  2. E = typing.TypeVar('E')
  3.  
  4. @sum_type
  5. class Result(typing.Generic[R, E]):
  6.     """Experimental generic ADT."""
  7.  
  8.     __slots__ = ()
  9.  
  10.     Ok: Ctor[R]
  11.     Err: Ctor[E]
  12.  
  13. my_result: Result[int, str] = Result.Ok(10)
  14.  
  15. @sum_type
  16. class ConcreteResult:
  17.  
  18.     __slots__ = ()
  19.  
  20.     Ok: Ctor[int]
  21.     Err: Ctor[str]
  22.  
  23. my_concrete_result: ConcreteResult = ConcreteResult.Ok(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement