Proving Composition Law for Maybe Applicative

前端 未结 4 1864
旧巷少年郎
旧巷少年郎 2021-01-12 21:19

So, I wanted to manually prove the Composition law for Maybe applicative which is:

u <*> (v <*> w) = pure (.) <*> u <*> v <*> w         


        
4条回答
  •  一个人的身影
    2021-01-12 21:47

    The rules that are generated by the definition of Maybe are

    x :: a
    ---------------
    Just x :: Maybe a
    

    and

    a type
    -----------------
    Nothing :: Maybe a
    

    Along with

    a type
    ------------------
    bottom :: a
    

    If these are the only rules which result in Maybe A then we can always invert them (run from bottom to top) in proofs so long as we're exhaustive. This is argument by case examination of a value of type Maybe A.

    You did two cases analyses, but weren't exhaustive. It might be that u or v are actually Nothing or bottom.

提交回复
热议问题