Questions tagged [tagless-final]

The approach is an alternative to the traditional encoding of an object language as a (generalized) algebraic data type.

Typed final (tagless-final) style

42 questions
2
votes
1 answer

Could not find implicit in Scala Tagless Final, Implicit, unit test

Getting: Error:(20, 5) could not find implicit value for parameter console: example.Console[F] new NameThing().program Error:(20, 5) not enough arguments for constructor NameThing: (implicit evidence$1: cats.Monad[cats.package.Id], implicit…
jakstack
  • 2,143
  • 3
  • 20
  • 37
2
votes
2 answers

Implementing Tagless Final Encoding in F# with SRTP

I'd like to transform my F# OOP version of Tagless Final into a typical FP approach and I'm thinking to use Statically Resolved Type Parameters of Type Classes from OO. What I've done is open System open FSharpPlus type UserName = string type…
user10794413
2
votes
1 answer

Tagless final example in Scala requires superfluous second interp arg

I'm playing around with implementing a tagless final DSL & interpreter in Scala, based on this blog post written in Haskell. I can get an example running - see code below, but I don't quite understand why I need testVal(Interp)(Interp). If I only…
jon hanson
  • 8,722
  • 2
  • 37
  • 61
2
votes
0 answers

trouble encoding system f omega in final tagless in idris

so I am trying to do system f omega in final tagless style. I had encoded system f successfully, as the following code (some example are also given)(also, please ignore the fact that inference is not working and the examples are very ugly, I will…
1
vote
2 answers

Scalatestplus scalacheck for testing effectful api requires unsafeRunSync()

I am exploring options to implement tests for effectful api. For brevity, I have the following api. object util { import cats.effect.Sync def stringReverser(string: String): String = string.reverse def stringReverserF[F[_]:…
nashter
  • 1,181
  • 1
  • 15
  • 33
1
vote
1 answer

Scala : Is there a more concise way to compose the following higher kind method?

UserRepository trait has two methods isRegistered and insert. trait UserRepository[F[_]] { def insert(user: domain.User): F[Long] def isRegistered(user: domain.User): F[Boolean] } Boundary class is the boundary of the core application. For this…
nashter
  • 1,181
  • 1
  • 15
  • 33
1
vote
1 answer

How convert Cats Effect 3 to Future

I'm trying to combine Playframework with Cats Effect 3 Tagless Final style. I'm stuck on the transformation to the Future. Play's Action requires either just value or Future, which I want to reach, for async processing. def method = authed { _ => …
skilgal
  • 172
  • 1
  • 4
  • 14
1
vote
1 answer

Scala Cats: How to test logging vs how to log in production code

Could you give me a tagless-final version in Scala, of a logging implementation that is easily testable in unit tests but runs with slf4j or similar frameworks in production?
Hunor Kovács
  • 1,062
  • 9
  • 16
1
vote
1 answer

How to write unit test for my tagless algebra?

I have an interpreter for an algebra and I would like to write a unit test for it. The interpreter is as follows: final case class LiveDbConnector[F[_] : MonadError[*[_], Throwable]](env: Environment[F]) extends DbConnector[F] { override def…
softshipper
  • 32,463
  • 51
  • 192
  • 400
1
vote
1 answer

Transform Future[A] to F[A] with Async[F]

I'm working with Slick and Cats. database.run returns a Future, but I need the method of my class (generic on F[_]: Async) to return a monad F. I can make it work like this val future = database.run(insertion) val result = Await.result(future,…
marcopiii
  • 793
  • 7
  • 25
1
vote
1 answer

Scala Cats: tail recursive tailRecM method for Monad Instance of Task[Validated[String,?]

In cats, when a Monad is created using the Monad trait, ideally a tail-recursive implementation for method tailRecM should be provided to ensure stack safety. I am using the tagless final approach and wish to have an effect of Task[Validated[String,…
1
vote
1 answer

Transform F[A] to Future[A]

I have a repository: trait CustomerRepo[F[_]] { def get(id: Identifiable[Customer]): F[Option[CustomerWithId]] def get(): F[List[CustomerWithId]] } I have an implementation for my database which uses Cats IO, so I have a…
Sebastian
  • 16,813
  • 4
  • 49
  • 56
0
votes
1 answer

In scala property based tests for tagless final with variable inerpreter

I have the following algebra // domain case class User(id: String, name: String, age: Int) // algebra trait UserRepositoryAlgebra[F[_]] { def createUser(user: User): F[Unit] def getUser(userId: String): F[Option[User]] } I have a…
nashter
  • 1,181
  • 1
  • 15
  • 33
0
votes
1 answer

How to define polymorphic tagless final lists

After reading the excellent and interesting paper Typed Tagless-Final Interpretations: Introductory Course from Oleg Kiselyov I tried to convert normal Haskell lists to Tagless Final lists and failed: This is working: {-# LANGUAGE FlexibleInstances…
Jogger
  • 1,617
  • 2
  • 12
  • 22
0
votes
1 answer

Scala Tagless Final - Not compiling

This is a basic Scala Tagless Final pattern implementation of a contrived login process. It doesn't compile because as it shows near the end 'No implicits found for parameters ...' But if I remove ': Monad: LoginProcessAlgebra[F]' from the program…
jakstack
  • 2,143
  • 3
  • 20
  • 37