Adding a new exercise and solution to Section 5.1#83
Conversation
|
Thanks for adding this. To avoid having to use primed function names, you could put everything in its own namespace: namespace Ex2
data Failure : Type where
UnknownUser : Email -> Failure
InvalidPassword : Failure
AccessDenied : Email -> Album -> Failure
handleRequest : DB -> Request -> Either Failure Album
handleRequest db req = case find (\u1 => u1.email == req.credentials.email) db of
Nothing => Left (UnknownUser req.credentials.email)
Just u2 => case (u2.email == req.credentials.email && u2.password == req.credentials.password) of
False => Left InvalidPassword
True => case elem req.album u2.albums of
False => Left (AccessDenied req.credentials.email req.album)
True => Right req.album |
|
Thank you, I didn't think of that. And in hindsight |
|
I wasn't sure how to handle the fact that this branch was created before but submitted after the other pull request. So I manually changed the |
Please don't do this. Git is able to deal with this kind of thing automatically. Otherwise, the preferred way to do this would be a rebase. Now, in order not to further complicate things, you can leave things as they currently are. So, once the linting issues are fixed (there seems to be some trailing whitespace), this should be ready for merging. |
Hi! I was playing around with the server example in Section 5.1 and I think it would make a nice exercise. I refactored
handleRequestto useEither. I found it a nice challenge that helped make me more comfortable with parametric types. This pull request:I did have to append some values with an apostrophe (e.g.
handleRequest',UnknownUser') to get it to compile in the same file as the solution to the previous exercise.Thank you for the tutorial. I'm really enjoying it. For me at least the exercises are the most helpful part.