score:0
A monoid is a set with some operations that obey particular laws. What elements are you considering as possible HListM[A]
? If you declare HListM[A] = HList
, i.e. any HList
, then you'll quickly find that you can't map
with f: A => B
, except by treating all map
s as identity
and you've reinvented the rather uninteresting monad Id
(with a few extra but inert inhabitants).
We could make a monad with the type HListM[A] = A :: ... :: A :: HNil
(though even actually expressing that type in Scala is a challenge - you'd need an auxiliary trait trait CopiesOf[N <: Nat, A] {type Out <: HList
}, implicit
s to provide instances of this, and then an existential to actually write it (CopiesOf[N, A]#Out forSome {type N <: Nat}
)). Writing monad operations for this is possible, though you'd need to require shapeless auxiliary classes like Prepend
at the point of operation, since there's no real way to express a "forall" type in Scala - you can declare instances of your type for _0
and Succ[N]
, but there's no way to prove to the compiler that there is an instance for any N <: Nat
, you just have to require implicit ones whenever you need to use them.
But after a lot of work you'd end up with something isomorphic to List[A]
; why not just use List[A]
for that case?
Source: stackoverflow.com
Related Query
- Define scalaz monad instance for a shapeless hlist
- Find type class instance for Shapeless HList in Scalaz state monad
- Scalaz iteratees: "Lifting" `EnumeratorT` to match `IterateeT` for a "bigger" monad
- Extractor for a shapeless HList that mimics parser concatenation `~`
- Shapeless define lens for base trait
- Define a Typeclass for Shapeless Records
- Find type class instances for Shapeless HList
- Scalaz - combining List and State Monad in for comprehension
- Why is there no Functor instance for Array in Scalaz
- Generic Poly2 Folder case for shapeless Hlist
- Why Free is not monad instance in Scalaz 7.1.5?
- Shapeless find instance of Some among Nones in an Hlist of Options
- No Monad Instance for `Data.Map`, but Scala's Map?
- How can I define an HKT for instance (over object) methods in Scala?
- Shapeless type inference for HList does not work
- Test two scala shapeless HList types for equivalence via implicit
- How to define a Monad for a function type?
- Scala doesn't derive dependent type for shapeless HList (using Aux)
- How to define typeclass instance for higher kinded types in Scala?
- How to apply a list of modifciations on a scalaz State Monad without for comprehension
- Applicative instance for Reader monad
- Why there is no Semigroup instance for TrieMap in scalaz
- How do I define a function for a Monad Stack of State, Disjunction, and List?
- type class NumberLike instance for Coproduct with shapeless
- How can I define an instance of a typeclass in scala that can be used for all subclasses of a particular type?
- scalaz Free Monad control break and pause for a chain of computations
- Easy idiomatic way to define Ordering for a simple case class
- Reader Monad for Dependency Injection: multiple dependencies, nested calls
- Scalaz state monad examples
- Using Scalaz Stream for parsing task (replacing Scalaz Iteratees)
More Query from same tag
- How can I accessing the scala play plugin from Build.scala
- Importance of the caching [Spark]
- Iterate over row and create batch: DataFrame
- Scala, a cross between a foldLeft and a map supporting lazy evaluation
- cqlsh 'Select' statement does not return the data that exists
- Illegal inheritance while extending trait with self type
- In Scala, how would I combine event driven programming with a functional approach?
- How to drop nested column or filter nested column in scala
- Why intercept command is not not working on scala 2.11.7
- Scala pattern matching with tuple: matching equal values in the tuple
- Gatling Gradle Build to add scala Simulations and Config files as Fatjar
- Cannot resolve reference StructField with such signature
- spray json implicit UUID conversion
- How to factor out main method of Scala objects into a shared location?
- What are the features of dynamic languages (like Ruby or Clojure) which you are missing in Scala?
- Scala covariant type T occurs in invariant position
- Calling JDBC to impala/hive from within a spark job and creating a table
- Scala spark thorws ArrayOutOfBound exception on count,show function
- Play 2.6x Scala app does not log despite logback configuration
- Filtering a map of type [String, Seq[Int]] by value
- How to convert all column of dataframe to numeric spark scala?
- How can I create a mapping function for 1000 elements in scala
- Convert a DataFrame to another with "case class" type
- case class to shapeless Generic conversion
- Scala's notion of "partial functions"' & the ".orElse" method in F#
- Throwing exception when Actor returns Future[Option[None]] Akka Http
- Using mutable Before/After/Around in Specs2
- How can I have a method parameter with type dependent on an implicit parameter?
- In Scala, how to work around TraversableLike.toIterator's inefficient intermediate Stream
- Scala/Play: Assigning a value that's not there yet