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
11
votes
0 answers

Tagless final DSL with RValue LValue problems

Typed Tagless Final Interpreters are an interesting alternative to the free monad approach. But even with a quite simple ToyLang example in tagless final style ambiguous type variables pop up. ToyLang is an EDSL that should read something like…
mcmayer
  • 1,931
  • 12
  • 22
11
votes
1 answer

Typeclass dependency with tagless-final

After watching John De Goes' "FP to the Max" (https://www.youtube.com/watch?v=sxudIMiOo68) I'm wondering about approaches for writing FP programs in the tagless-final pattern. Say I have some typeclass for modelling a side-effecty thing (taking his…
amitayh
  • 770
  • 1
  • 8
  • 19
9
votes
1 answer

Is it ok to use Tagless Final (Object Algebras) on coalgebras?

Background The Haskell and Scala community have been very enamored recently with what they call tagless final 'pattern' of programming. These are referenced as dual to initial free algebras, so I was wondering what Tagless Final was final of. On…
8
votes
1 answer

Validation and capturing errors using an algebra

I came across this article on medium: https://medium.com/@odomontois/tagless-unions-in-scala-2-12-55ab0100c2ff. There is a piece of code that I have a hard time understanding. The full source code for the article can be found here:…
boggy
  • 3,674
  • 3
  • 33
  • 56
5
votes
1 answer

Elegant way to change either to error with tagless final

I often do things like: import cats.effect.Sync import cats.implicits._ case class User(name: String) case object Error extends Exception def validate[F[_]: Sync](name: String): F[Either[Error, User]] = Sync[F].pure(User(name).asRight) def…
5
votes
1 answer

Tagless-final effect propagation

The tagless-final pattern lets us write pure functional programs which are explicit about the effects they require. However, scaling this pattern might become challenging. I'll try to demonstrate this with an example. Imagine a simple program that…
amitayh
  • 770
  • 1
  • 8
  • 19
3
votes
1 answer

Avoid boilerpate of tagless final in Haskell

The following code shows a tagless final lambda typeclass and an evaluation instance: class Lambda (repr :: * -> *) where int :: Int -> repr Int add :: repr Int -> repr Int -> repr Int lambda :: forall a b. (repr a -> repr b) -> repr (a…
Jw C
  • 171
  • 2
  • 6
3
votes
2 answers

Can't code my component in a tagless-final way / using type classes and instances

(This is the concrete case behind How do I conditionally declare an instance?) In my small project players can create/join/watch a game session or list the ongoing sessions. A very simple Yesod app exposes some endpoints to match the use-cases. Step…
Ashkan Kh. Nazary
  • 21,844
  • 13
  • 44
  • 68
3
votes
1 answer

Conversion between Option[F[ShoppingCart]] to F[Option[ShoppingCart]]

I have the following algebra in Scala (I am using the Tagless Final Pattern): trait ShoppingCarts[F[_]] { def create(id: String): F[Unit] def find(id: String): F[Option[ShoppingCart]] def add(sc: ShoppingCart, product: Product):…
3
votes
2 answers

How to configure Cats Timer on abstract effect type

Let's say I have a following method signature in a project using Cats-effect and tagless final approach: def schedule[F[_]: Applicative : Async: Timer] I'm trying to schedule an operation on a schedule method call using pure FP. I tried this…
3
votes
2 answers

Problem with Cats FlatMap in my Tagless Final class

I have the following class: class MyBot[F[_] : FlatMap] In this class I have a function: private def handleCallback(): F[Boolean] In my understanding this should work: handleCallback().flatMap(..) But it throws: cannot resolve symbol flatMap What…
pme
  • 14,156
  • 3
  • 52
  • 95
2
votes
2 answers

Kleisli dependencies with Tagless Final style

I am trying to model a dependency using Kleisli. For instance, let's imagine I have the following business logic types: import $ivy.`org.typelevel:cats-core_2.13:2.2.0` import cats._ import cats.implicits._ trait Decoder[F[_]] { def decode(s:…
Dmytro Mykhailov
  • 249
  • 1
  • 3
  • 14
2
votes
2 answers

Converting an `Option[A]` to an Ok() or NotFound() inside an Http4s API

I've got an API that looks like this: object Comics { ... def impl[F[_]: Applicative]: Comics[F] = new Comics[F] { def getAuthor(slug: Authors.Slug): F[Option[Authors.Author]] = ... and a routing that looks like this: object Routes…
sshine
  • 15,635
  • 1
  • 41
  • 66
2
votes
1 answer

Two polymorphic classes in one function

I have this code with State monads: import Control.Monad.State data ModelData = ModelData String data ClientData = ClientData String act :: String -> State ClientData a -> State ModelData a act _ action = do let (result, _) = runState action $…
esp
  • 7,314
  • 6
  • 49
  • 79
2
votes
1 answer

Scala, cats - how to create tagless-final implementation with IO (or other monad) and Either?

I have created a simple trait and his implementation: trait UserRepositoryAlg[F[_]] { def find(nick: String): F[User] def update(user: User): F[User] } class UserRepositoryInterpreter extends UserRepositoryAlg[Either[Error, *]] { override…
Developus
  • 1,400
  • 2
  • 14
  • 50
1
2 3