Appropriate for Halloween! But what really scares me about Haskell isn't the scary syntax, ghastly features, and Lovecraftian cosmic horror terminology; it's that it has somehow become the epitome of functional programming when bash pipelines are the functional mode that people use more than any other and people don't even realize it.
ExactlyOne would be called the Identity functor. It is used when you need a functor, but all you want is a trivial one (like a no-op, or a passthrough).
in monad transformer stacks, we use the Identity functor for the base of an otherwise pure stack -- transformers require their inner monad to be a monad in itself, and Identity allows us to lift a pure value into a monadic context without removing its pure semantics. An example might be `ExceptT ApplicationError (StateT ApplicationState (Identity a))` for a pure computation, that can throw some Application Error, and has some state ApplicationState. Granted `StateT s (Identity a)` is just a synonym for `State s a`, but the former allows you to abstract over the type of state monad you use (Lazy, Strict, etc.)
Strictly, it's Solo, not Identity, since Identity is defined as a newtype (which improves performance but changes its laziness behavior). Identity is used to provide a dummy monadic type for monad transformers (types that take a monadic type and apply another monadic type over it, combining their characteristics)
The thing that I think might be missing here is the notion that Applicative is a generalization of fmap from functions of 1 argument to functions of zero (pure) or more (, using currying) arguments. There is a good overview on this perspective from Graham Hutton: ua-cam.com/video/8oVHISjS3wI/v-deo.htmlsi=ovW6JvN5XJ294SY0
Appropriate for Halloween! But what really scares me about Haskell isn't the scary syntax, ghastly features, and Lovecraftian cosmic horror terminology; it's that it has somehow become the epitome of functional programming when bash pipelines are the functional mode that people use more than any other and people don't even realize it.
Man you have the perfect voice. Like if you did audiobooks, chef kiss
Thank you so much for the compliment! Maybe some day if I need a second career…
ExactlyOne would be called the Identity functor. It is used when you need a functor, but all you want is a trivial one (like a no-op, or a passthrough).
in monad transformer stacks, we use the Identity functor for the base of an otherwise pure stack -- transformers require their inner monad to be a monad in itself, and Identity allows us to lift a pure value into a monadic context without removing its pure semantics.
An example might be `ExceptT ApplicationError (StateT ApplicationState (Identity a))` for a pure computation, that can throw some Application Error, and has some state ApplicationState. Granted `StateT s (Identity a)` is just a synonym for `State s a`, but the former allows you to abstract over the type of state monad you use (Lazy, Strict, etc.)
Strictly, it's Solo, not Identity, since Identity is defined as a newtype (which improves performance but changes its laziness behavior).
Identity is used to provide a dummy monadic type for monad transformers (types that take a monadic type and apply another monadic type over it, combining their characteristics)
The thing that I think might be missing here is the notion that Applicative is a generalization of fmap from functions of 1 argument to functions of zero (pure) or more (, using currying) arguments. There is a good overview on this perspective from Graham Hutton: ua-cam.com/video/8oVHISjS3wI/v-deo.htmlsi=ovW6JvN5XJ294SY0
This is an interesting way to think about it, and one I had not considered.