The common mistake is to choose too powerfull type.
Effect => Such a type can represent anything
Consequences => Tends to corrupt, illegal state, wrong buisness model representation, "strange" runtime errors, lost time, ...
Action point => ???
In computer programming, more so functional programming and type theory, an algebraic data type is a kind of composite type, i.e., a type formed by combining other types.
Source Wikipedia
a | b = |a| + |b|
(a, b) = |a| * |b|
a -> b = |b| ^ |a|
|Void| = 0
|()| = 1
|Bool| = 2
-- Let`s check the cardinalities for ::
type Product = |(Bool, Bool)| = ???
type Sum = |Either Bool Bool| = ???
type Exponential = |(Bool -> Bool)| = ???
Two different types A and B with the same cardinalities are isomorphisms between each other.
We are able to express mathematical theorems in terms of types!
(a * b)^c = a^c * b^c
a * ( b + c ) = a * b + a * c
-- not that easy
(a^b)^c = a ^ (b * c)
TODO ::
1. prove that
a * 1 = a | a ^ 1 = a by Curry-Howard
2. import Data.Void - discussion about absurd
aType = ∑ ∏ aType m, n
So the canonical form is represent as a Sum of products
-- correct canonical from ::
Either a b
a -> b
Either a (Either b, (c,d))
-- not correct ::
(a, Either b c)
(a, Bool)
“A Profunctor is a Contravariant Functor on its first type parameter and a Functor on its second type parameter.”
Source TypeLevel::Cats API
data Variance = Covariant | Contravariant | Invariant
A Variance of type T a is fully specified by positive, negative (or mix of both) type variable position.
newtype F1 a = F1 ( Int -> a ) -- + => + Covariant
newtype F2 a = F2 ( a -> a ) -- +/- => +/- Invariant
newtype F3 a = F3 ((Int -> a) -> Int ) -- Contravariant - * + => -
newtype F4 a = F4 ((a -> Int) -> Int ) -- Covariant - * - => +
¿Why?
Becasue writing like this we programming by giving proofs.
¡Think about it!
STOP String data modeling
Well type data ~ More free time for all!
No State -> No ClassesFind us
sealed trait SocialMedia
case object Telegram extends SocialMedia
case object Meetup extends SocialMedia
case object Twitter extends SocialMedia
aMalagaScalaSocial match {
case Twitter => https://twitter.com/MalagaScala
case Telegram => https://t.me/malaga_scala
case Meetup => https://meetup.com/Malaga-Scala
case _ => ???
}