anchor.diff:    | UsernameAlreadyExists
     | Error of Error
   
  -  type CreateUserResponse = {
  -    UserId : UserId
  -    VerificationCode : VerificationCode
  -  }
     type CreateUser = 
  -    CreateUserRequest -> AsyncResult<CreateUserResponse, CreateUserError>
  +    CreateUserRequest -> AsyncResult<UserId, CreateUserError>
   
     type SignupEmailRequest = {
       Username : Username
  
positive.code:       Email = req.EmailAddress
        VerificationCode = verificationCode
      }
      let! res = 
        createUser createUserReq
        |> mapAsyncFailure CreateUserError 
  
  
negative.code: 
    let signupTemplatePath = "user/signup.liquid" 
  
    let handleCreateUserError viewModel = function
    | EmailAlreadyExists ->
      let viewModel = {viewModel with Error = Some ("email already exists")}
      page signupTemplatePath viewModel
    | UsernameAlreadyExists ->
      let viewModel = {viewModel with Error = Some ("username already exists")}
      page signupTemplatePath viewModel
    | Error ex ->
      printfn "Server Error : %A" ex
      let viewModel = {viewModel with Error = Some ("something went wrong")}
      page signupTemplatePath viewModel
  
    let mapUserSignupResult viewModel = function
    | Ok _ -> Redirection.redirect "/"
    | Bad errs ->
      match List.head errs with
      | CreateUserError cuErr ->
        handleCreateUserError viewModel cuErr
      | SendEmailError seErr ->
        printfn "error while sending email : %A" seErr
        Redirection.redirect "/"
    
    let handleUserSignupReq signupUser viewModel = 
      signupUser  
      >> Async.ofAsyncResult 
      >> Async.map (mapUserSignupResult viewModel)
  
    let handleUserSignup singupUser ctx = async {
      match bindEmptyForm ctx.request with
      | Choice1Of2 (vm : UserSignupViewModel) ->
        let result =
          UserSignupRequest.TryCreate (vm.Username, vm.Password, vm.Email)
        match result with
        | Ok (userSignupReq, _) ->
          let! webpart = handleUserSignupReq singupUser vm userSignupReq
          return! webpart ctx
        | Bad msgs ->
          let viewModel = {vm with Error = Some (List.head msgs)}
          return! page signupTemplatePath viewModel ctx
      | Choice2Of2 err ->
        let viewModel = {emptyUserSignupViewModel with Error = Some err}
        return! page signupTemplatePath viewModel ctx
    }
  
    let webPart () =
      let createUser = Persistence.createUser
      let sendEmail = Email.sendSignupEmail
      let singupUser = Domain.signupUser createUser sendEmail
      path "/signup" 
        >=> choose [
          GET >=> page signupTemplatePath emptyUserSignupViewModel
          POST >=> handleUserSignup singupUser
        ]
        
  
  