{"action":"closed","issue":{"url":"https://api.github.com/repos/michaelochurch/summer-2015-haskell-class/issues/4","labels_url":"https://api.github.com/repos/michaelochurch/summer-2015-haskell-class/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/michaelochurch/summer-2015-haskell-class/issues/4/comments","events_url":"https://api.github.com/repos/michaelochurch/summer-2015-haskell-class/issues/4/events","html_url":"https://github.com/michaelochurch/summer-2015-haskell-class/issues/4","id":100491436,"number":4,"title":"Haskell Lecture #5","user":{"login":"mikemcgowan","id":2492670,"avatar_url":"https://avatars.githubusercontent.com/u/2492670?v=3","gravatar_id":"","url":"https://api.github.com/users/mikemcgowan","html_url":"https://github.com/mikemcgowan","followers_url":"https://api.github.com/users/mikemcgowan/followers","following_url":"https://api.github.com/users/mikemcgowan/following{/other_user}","gists_url":"https://api.github.com/users/mikemcgowan/gists{/gist_id}","starred_url":"https://api.github.com/users/mikemcgowan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikemcgowan/subscriptions","organizations_url":"https://api.github.com/users/mikemcgowan/orgs","repos_url":"https://api.github.com/users/mikemcgowan/repos","events_url":"https://api.github.com/users/mikemcgowan/events{/privacy}","received_events_url":"https://api.github.com/users/mikemcgowan/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-08-12T08:17:07Z","updated_at":"2015-08-12T14:32:49Z","closed_at":"2015-08-12T14:32:48Z","body":"Hi,\r\n\r\nIt looks like there's a mistake on slide 71 of [Haskell Lecture #5](https://docs.google.com/presentation/d/1Yx02f9OUSoaFgKCIg0uApZa9wuR-cIQk7b1Y_Hkg-4E/edit#slide=id.ga2fded44c_0_8).\r\n\r\nIf I add the necessary wrapping of values in the `case` expression, the code that compiles is:\r\n\r\n```\r\nnewtype MyLast a  = MyLast  { getMyLast  :: Maybe a }\r\n\r\ninstance Monoid (MyLast a) where\r\n    mempty = MyLast Nothing\r\n    mappend (MyLast m1) (MyLast m2) =\r\n        case (m1, m2) of\r\n            (Nothing, x) -> MyLast x\r\n            (_, Just v)  -> MyLast $ Just v\r\n```\r\n\r\nHowever, the following gives a *Non-exhaustive patterns in case* exception in ghci:\r\n\r\n```\r\nlet myLast1 = MyLast $ Just 123\r\nlet myLast2 = MyLast Nothing\r\nmyLast1 `mappend` myLast2\r\n```\r\n\r\nInstead, `MyLast a` should be an instance of `Monoid` as follows:\r\n\r\n```\r\nnewtype MyLast a  = MyLast  { getMyLast  :: Maybe a }\r\n\r\ninstance Monoid (MyLast a) where\r\n    mempty = MyLast Nothing\r\n    mappend (MyLast m1) (MyLast m2) =\r\n        case (m1, m2) of\r\n            (x, Nothing) -> MyLast x\r\n            (_, Just v)  -> MyLast $ Just v\r\n```\r\n\r\ni.e. the first pattern in the `case` expression on the slide has its tuple elements the wrong way around.\r\n\r\nThanks!"}}