sorry gif this is an obvious question but with so little understanding of how a computer chip actually works I have a question to ask
what is the Haskell equivalent of “for” or “is defined for” in set theory?
thanks in advance,
Oliver
sorry gif this is an obvious question but with so little understanding of how a computer chip actually works I have a question to ask
what is the Haskell equivalent of “for” or “is defined for” in set theory?
thanks in advance,
Oliver
Knowing some set theory proper, I’m not sure what you mean by “is defined for” in it. Perhaps you are referring to functions which are only defined on some inputs. If so, in Haskell, we prefer to define total functions but limit their domains by making use of types. So perhaps type signatures are what you want.
You will need to explain your question in more detail to get a more helpful answer.
But also, if this is the sort of thing you are thinking about, you may be interested in the (unfortunately rather old) book The Haskell Road to Logic, Maths and Programming
https://wikimedia.org/api/rest_v1/media/math/render/svg/1776e4400b5a4bb560ae7fc9daff4a8a87358da5
You’re right its the same as type signatures
The type signature that corresponds to 2^N (or rather, to possibly infinite streams of 2 (i.e. bool)) is [Bool]. One can also define infinite streams, and have a signature of Stream Bool
, and one can also just view this as the functions of the type Integer -> Bool
(if we squint our eyes and pretend the Integer type is truly infinite, and ignore the values below 1).
I will note that using set builder notation to actually comprehensively enumerate all elements of this particular thing is quite a bit trickier.
Here you’re using “for” to give a declaration of an infinite structure. In Haskell, we declare infinite structures (co)inductively. So there’s no special notation I can think of that makes this particularly look like the equation you gave. For finite structures in simple cases, list-comprehension notation can parallel set builder notation (although it has no notion of “for”).
For a finite structure, you could write the elegant (but nonobvious at first) sequence (replicate 10 [True, False])
(and of course replace 10 by any integer you prefer.)
For a nonfinite structure, you need to be quite a bit more clever. Recall that by cantor, 2^N is not in bijection with N, so while it is possible to do, many obvious approaches will not work as you might expect.