Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter4 answers #4

Merged
merged 3 commits into from
Oct 29, 2021
Merged

Chapter4 answers #4

merged 3 commits into from
Oct 29, 2021

Conversation

aiwaverse
Copy link
Owner

Solutions for Chapter 4

The final chapter! And the one with content I always struggled, but was very good to understand with your explanations!

cc @vrom911 @chshersh

Copy link

@chshersh chshersh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Fantastic work!
Thank you so much for taking this course! I hope you had fun 🕺 🎤

We would really appreciate your feedback on the course!

You can also ask any questions @vrom911 or me and we can discuss any topics you would like to dig into as well 🙂 Don't be a stranger!


If you would like to continue your journey to Haskell, check out our Haskell Knowledge Map for the list of topics to explore 🗺️

@@ -267,7 +276,8 @@ instance Functor Maybe where
fmap _ x = x
@
-}

-- The type of x is a, and that implementation does not change the
-- type of a to b, so the return type is wrong

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely correct 💯


(<*>) :: Secret e (a -> b) -> Secret e a -> Secret e b
(<*>) = error "(<*>) Secret: Not implemented!"
Trap e <*> _ = Trap e
Reward f <*> x = f <$> x

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work on reusing Functor instance for Secret! 🗺️

Comment on lines +668 to +671
-- weird expected behavior, I personally assumed it would be the same as
-- liftM2 (&&), but that was not the case
andM :: (Monad m) => m Bool -> m Bool -> m Bool
andM = error "andM: Not implemented!"
andM b1 b2 = b1 >>= (\b -> if not b then pure b else (&&) b <$> b2)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ordinary && if lazy on the second argument. Meaning that if it meets False as the first argument, there is no need to calculate another arg. In andM we would like to keep the same behaviour, so the

Just False `andM` _

should be Just False 🙂

@@ -673,7 +712,24 @@ Specifically,
❃ Implement the function to convert Tree to list
-}

-- this felt a little easy for a final boss xD

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aiwaverse
Copy link
Owner Author

Thank you very much for all the help and the course.

@aiwaverse aiwaverse merged commit 3ae3323 into main Oct 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants