[GHC] #10082: Church Booleans - xor

GHC ghc-devs at haskell.org
Wed Feb 11 23:22:22 UTC 2015


#10082: Church Booleans - xor
-------------------------------------+-------------------------------------
        Reporter:  honza889          |                   Owner:
            Type:  bug               |                  Status:  closed
        Priority:  normal            |               Milestone:
       Component:  Compiler          |                 Version:  7.9
      Resolution:  invalid           |                Keywords:
Operating System:  Linux             |            Architecture:  x86_64
 Type of failure:  Incorrect result  |  (amd64)
  at runtime                         |               Test Case:
      Blocked By:                    |                Blocking:
 Related Tickets:                    |  Differential Revisions:
-------------------------------------+-------------------------------------
Changes (by simonpj):

 * status:  new => closed
 * resolution:   => invalid


Comment:

 You are trying to use higher rank types here, so you need type signatures.
 (See [http://research.microsoft.com/en-us/um/people/simonpj/papers/higher-
 rank/index.htm Practical type inference for higher rank types]).  This
 works:
 {{{
 {-# LANGUAGE RankNTypes #-}
 module T10082 where

 type CBool = forall a. a->a->a
 lTrue :: CBool
 lTrue = \x y -> x

 lFalse :: CBool
 lFalse = \x y -> y

 lNot :: CBool -> CBool
 lNot = \t -> t lFalse lTrue

 lXor :: CBool -> CBool -> CBool
 lXor = \u v -> u (lNot v) (lNot (lNot v))  -- You omitted some parens
 here!

 lXor' :: CBool -> CBool -> CBool
 lXor' = \u v -> u (v lFalse lTrue) (v lTrue lFalse)

 lXor'' :: CBool -> CBool -> CBool
 lXor'' = \u v -> u (lNot v) (v)

 lXor''' :: CBool -> CBool -> CBool
 lXor''' = \u v -> u (lNot v) v
 }}}
 So it all seems fine to me. I'll close as invalid but do re-open if you
 disagree.

 Simon

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10082#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list