, Quad= 4 Quad -> Quad= 4 4. , , 256 Quad -> Quad.
4 4= 4 & times; 4 ; 4 ; 4. (Quad, Quad, Quad, Quad). :
type Quad4 = (Quad, Quad, Quad, Quad)
tupleToFunction :: Quad4 -> (Quad -> Quad)
tupleToFunction (a, b, c, d) x = case x of
One -> a
Two -> b
Three -> c
Four -> d
functionToTuple :: (Quad -> Quad) -> Quad4
functionToTuple f = (f One, f Two, f Three, f Four)
: Quad4 4- 4, 0000 4= 0 = (One, One, One, One) 3333 4= 255 = (Four, Four, Four, Four).
. , ; "" . , Quad -> Quad Word8!
You can also do this by extending the product type (tuple) to the sum types ( Either). For Quadit would be great, but here is how you did it with Bool -> Bool= 2 2 = 2 & times; 2 = 2 + 2:
type BB = Either Bool Bool
eitherToFunction :: BB -> (Bool -> Bool)
eitherToFunction (Left a) _ = a
eitherToFunction (Right a) b = a == b -- xnor
Now we can imagine const Truehow Left True, const Falsehow Left False, idhow Right Trueand nothow Right False, and we write the other half of the isomorphism, respectively
functionToEither :: (Bool -> Bool) -> BB
functionToEither f
| f True && f False = Left True
| f True = Right True
| f False = Right False
| otherwise = Left False