<commit_before>package nominal
package lib

import language.higherKinds

trait Monad extends Applicative {
  type Map[+X]

  // inherited from applicative
  def pure[A](x: A): Map[A]
  def call[A, B](f: Map[A => B], x: Map[A]): Map[B]

  // idiosyncratic to monad
  def join[A](x: Map[Map[A]]): Map[A]
  def bind[A, B](m: Map[A], f: A => Map[B]): Map[B]
}

object Monad {
  class View[M[+_]: Monad.ic, A](x: M[A]) {
    val monad = implicitly[Monad.ic[M]]
    import monad._
    def flatMap[B](f: A => M[B]): M[B] = bind(x, f)
    def map[B](f: A => B): M[B] = bind(x, pure[B] _ compose f)
  }

  type ic[M[+_]] = Monad { type Map[+X] = M[X] }
}

trait MonadWithBind extends Monad {
  // inherited from applicative
  def pure[A](x: A): Map[A]
  def bind[A, B](m: Map[A], f: A => Map[B]): Map[B]

  def call[A, B](f: Map[A => B], x: Map[A]): Map[B] =
    bind(f, (f: A => B) => fmap(f, x))

  def join[A](x: Map[Map[A]]): Map[A] =
    bind(x, (y: Map[A]) => y)
}<commit_msg>bug fix: this line caused `Compos.fresh2` to overflow the stack.<commit_after>package nominal
package lib

import language.higherKinds

trait Monad extends Applicative {
  type Map[+X]

  // inherited from applicative
  def pure[A](x: A): Map[A]
  def call[A, B](f: Map[A => B], x: Map[A]): Map[B]

  // idiosyncratic to monad
  def join[A](x: Map[Map[A]]): Map[A]
  def bind[A, B](m: Map[A], f: A => Map[B]): Map[B]
}

object Monad {
  class View[M[+_]: Monad.ic, A](x: M[A]) {
    val monad = implicitly[Monad.ic[M]]
    import monad._
    def flatMap[B](f: A => M[B]): M[B] = bind(x, f)
    def map[B](f: A => B): M[B] = bind(x, pure[B] _ compose f)
  }

  type ic[M[+_]] = Monad { type Map[+X] = M[X] }
}

trait MonadWithBind extends Monad {
  // inherited from applicative
  def pure[A](x: A): Map[A]
  def bind[A, B](m: Map[A], f: A => Map[B]): Map[B]

  def call[A, B](f: Map[A => B], x: Map[A]): Map[B] =
    bind(f, (f: A => B) => bind(x, (x: A) => pure(f(x))))

  def join[A](x: Map[Map[A]]): Map[A] =
    bind(x, (y: Map[A]) => y)
}
{'fraction_non_alphanumeric': 0.2251984126984127, 'fraction_numerical': 0.000496031746031746, 'mean_word_length': 3.4525386313465782, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7355905', 'n_tokens_mistral': 927, 'n_tokens_neox': 896, 'n_words': 245}