Is there a style class in haskell for boolean values?

I am trying to learn Haskell by looking at the excellent short and tutorial article on the comonad application from 2006, the link contains an expression like rule (U (a:_) b (c:_)) = not (a && b && not c || (a==b))whre U- this is the comonad zipper. This is indicated in data U x = [x] x [x]and related implementations of comonad operations.

Trying to learn more, I try to annotate the type of expression manually. A wise choice seems rule :: U Bool -> Bool, but it seems a little ... restrictive. I could imagine other types that could have truth values, such as Ints (0 corresponds to false, all other values ​​can be True) and others.

If there were a type class for the truth called truthy, I could write rule :: (Truthy t) => U t -> Bool. Since I want to iterate over rule, the annotation of the first type ( rule :: U Bool -> Bool) is good enough, but still the question tickles my brain.

Is there such a class? If there is, what is called? If not, then why is this not necessary?

+4
source share
1 answer

: , , , , (, + " " " ints" ) "" , ). , , , , , , . , "" , , .

, , ( ), Bits Data.Bits.

, :

-- note, the polymorphic `t` has cooties, and we'd need to be able to
-- make the caller polymorphic in a sensible way too for this to make sense
rule :: (Bits t) => U t -> t
rule (U (a:_) b (c:_)) = complement (a .&. b .&. complement c .|. complement (a `xor` b))

- a == b complement (a ``xor`` b). , (AND/OR/NOT), == :

a .==. b = complement ((a .|. b) .&. complement (a .&. b))

, ( , ), . - Int. Int, "" . , ? Bits - ?

: - : , . , Wolfram Alpha, , c ( , - ), :

rule (U (a:_) b _) = (a && not b) || (not a && b)

( c ?) .

+6

Source: https://habr.com/ru/post/1680748/


All Articles