Last active
          December 26, 2019 11:18 
        
      - 
      
- 
        Save happy-bracket/abe8a51fae4784717ac808f9c97870c4 to your computer and use it in GitHub Desktop. 
    TEA, but in Haskell
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | {-# LANGUAGE GADTs #-} | |
| module Main where | |
| newtype Login = Login String | |
| newtype Password = Password String | |
| data LoginState = Auth { | |
| login :: Login, | |
| password :: Password | |
| } | Nop | |
| data LoginMutation where | |
| Input :: Either Login Password -> LoginMutation | |
| LoginClicked :: LoginMutation | |
| data LoginEffect where | |
| TryLogin :: Login -> Password -> LoginEffect | |
| update :: LoginState -> LoginMutation -> (LoginState, [LoginEffect]) | |
| update s (Input (Left l)) = (s { login = l }, []) | |
| update s (Input (Right p)) = (s { password = p }, []) | |
| update s LoginClicked = (s, [TryLogin (login s) (password s)]) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | -- TEA with transactional-like mutations | |
| type Upd s m e = s -> m -> (s, [e]) | |
| data TMutation s e = TMutation { | |
| state :: s -> s, | |
| effs :: s -> [e] | |
| } | |
| type TUpd s e = Upd s (TMutation s e) e | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment