Ad
  • Custom User Avatar

    Hints to define isoUnMaybe

    I'm writing this comment since this is the function I had the most problems defining.

    I hope these hints help someone in my situation get into the mindset necessary to solve this on their own.

    Hint 1

    DO NOT READ UNTIL YOU TRIED THE PUZZLE BY YOURSELF

    The resulting function is total, even though it uses a non-total function in the code. It's up to the developer to prove (independently) that the result is total since the type-checker can't verify it on it's own.

    Hint 2

    DO NOT READ UNTIL YOU TRIED THE PUZZLE USING HINT #1

    Consider the relationship between the value Just a that the forward function (:: Maybe a -> Maybe b) sends to Nothing and the backward function (:: Maybe b -> Maybe a). Remember that both functions are supposed to form an isomorphism. What kind of relationship would the Null spaces of either
    Given the fact that the forward (:: Maybe a -> Maybe b) and backward (:: Maybe b -> Maybe a) form an isomorphism, consider the relationship between the value (Just a) which the forward function sends to Nothing and the backward function.

    Hint 3

    DO NOT READ UNTIL YOU TRIED THE PUZZLE USING HINT #2

    You might want to look into implementing the following special case:

    newtype Foo = Foo Int 
    newtype Bar = Bar Int
    
    isoMaybeFooBar :: ISO (Maybe Foo) (Maybe Bar)
    isoMaybeFooBar = (foobar, barfoo)
      where 
      foobar (Just (Foo x)) 
       | x == 0      = Nothing
       | otherwise   = Just (Bar x)
      foobar Nothing = Just (Bar 0)
      
      barfoo = error "try to implement this"
    
    isoUnMaybeFooBar :: ISO (Maybe Foo) (Maybe Bar) -> ISO Foo Bar 
    isoUnMaybeFooBar = error "try to implement this"