These are chat archives for typelevel/cats

21st
Jul 2016
Fabian Meyer
@fabianmeyer
Jul 21 2016 14:33
Hi, I have a case classe that is a simple pair of two Sets. I've defined a Monoid instance for the class, but can't fold over a list of it
  case class MappingResult(namespaces: Set[Namespace] = Set(), statements: Set[Statement] = Set())
  implicit val monoidInstanceForMappingResult: Monoid[MappingResult] = new Monoid[MappingResult] { }
mappingResults.fold => missing argument list for method fold in trait TraversableOnce Unapplied methods are only converted to functions when a function type is expected. You can make this conversion explicit by writing fold or fold(_)() instead of fold.
Merlin Göttlinger
@mgttlinger
Jul 21 2016 14:35
The compiler tries to use the fold method of the list which misses its arguments.
Fabian Meyer
@fabianmeyer
Jul 21 2016 14:37
and how to convince him to use cats.Foldable.fold instead of TraversableOnce.fold?
Merlin Göttlinger
@mgttlinger
Jul 21 2016 14:40
one way would be: Foldable[List].fold(mappingResults)
not sure if that is the best way though
Another way would be to define an implicit value class that provides the fold from Foldable under a name that is not present in the STDlib like foldMonoid or something like that.
Fabian Meyer
@fabianmeyer
Jul 21 2016 14:55
with a standard monoid like Set I am able to call foldK, but for my own monoid I get a
´´´
```
Cannot prove that de.hs_rm.cs.vs.traceability.importer.location.LocationMapper.MappingResult <:< G[A].
not enough arguments for method foldK: (implicit ev$macro$18: <:<[de.hs_rm.cs.vs.traceability.importer.location.LocationMapper.MappingResult,G[A]], implicit G: cats.MonoidK[G])G[A]. Unspecified value parameters ev$macro$18, G.
Cody Allen
@ceedubs
Jul 21 2016 15:01
@mgttlinger #831 tracks this
I think at the moment Foldable[List].fold(mappingResults) is probably the easiest solution
but it is a bit verbose
Merlin Göttlinger
@mgttlinger
Jul 21 2016 15:04
I would much rather like to have the methods gone from the STDlib :wink:
But I gues that is not an option...
Fabian Meyer
@fabianmeyer
Jul 21 2016 15:05
Sorry, I'm pretty new to scala. for the "Foldable[List].fold(mappingResults)" I get an "object Foldable does not take type parameters."
Cody Allen
@ceedubs
Jul 21 2016 15:06
@mgttlinger well if you really want the method to be gone, there is https://github.com/travisbrown/abstracted
I haven’t used it, but it’s an interesting concept
@fabianmeyer hmm and that’s Cats’ Foldable that you have in scope?
Fabian Meyer
@fabianmeyer
Jul 21 2016 15:07
@ceedubs : import cats.Foldable
Merlin Göttlinger
@mgttlinger
Jul 21 2016 15:09
@ceedubs There is absolutely no way I can convince the guys at work that hiding methods from the STDlib is a good idea.
Cody Allen
@ceedubs
Jul 21 2016 15:09
@fabianmeyer hmm I don’t know what’s going on there. It works for me:
scala> import cats.Foldable, cats.implicits._
import cats.Foldable
import cats.implicits._

scala> Foldable[List]
res0: cats.Foldable[List] = cats.instances.ListInstances$$anon$1@53c1e2df
any chance you are on a super old version of Cats or something?
@mgttlinger yeah, I don’t disagree :)
Fabian Meyer
@fabianmeyer
Jul 21 2016 15:12
cats 2.11 0.6.0
Fabian Meyer
@fabianmeyer
Jul 21 2016 15:21
@ceedubs : just updated to 0.6.1 and now it works
Peter Neyens
@peterneyens
Jul 21 2016 16:01
@fabianmeyer I think you can also do mappingResults.combineAll
Adelbert Chang
@adelbertc
Jul 21 2016 17:20

question for any Haskellers in the room. currently reading http://www.parsonsmatt.org/2016/07/14/rank_n_classy_limited_effects.html and i see at the bottom:

{-# LANGUAGE ConstraintKinds            #-}
{-# LANGUAGE DeriveFunctor              #-}
{-# LANGUAGE FlexibleInstances          #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses      #-}
{-# LANGUAGE PolyKinds                  #-}
{-# LANGUAGE RankNTypes                 #-}
{-# LANGUAGE UndecidableInstances       #-}

module Lib where

import           Control.Category
import           Control.Monad.Free
import           Control.Monad.IO.Class
import           Control.Monad.Reader
import           Prelude                hiding (id, (.))
import qualified Prelude                as P

newtype Interpret c d = Interpret (forall n a. d n => (forall m. c m => m a) -> n a)

instance Category Interpret where
  id = Interpret P.id
  Interpret f . Interpret g = Interpret $ \h -> f (g h)

as far as I can tell the kind of Interpret doesn't match up with Category, so is this just the work of PolyKinds ?

Rob Norris
@tpolecat
Jul 21 2016 17:40
blob
Adelbert Chang
@adelbertc
Jul 21 2016 17:42
@tpolecat transliterating Haskell code that contains PolyKinds and RankNTypes to Scala is uhh...... "interesting"
Srepfler Srdan
@schrepfler
Jul 21 2016 22:39
a lot of winking in functional programming @tpolecat
Rob Norris
@tpolecat
Jul 21 2016 22:52
also squinting and staring blankly