Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 07:47

    pakoito on master

    Fix MonadFilter docs (compare)

  • Sep 20 23:06
    pakoito edited #1614
  • Sep 20 23:06
    pakoito opened #1614
  • Sep 20 17:47
    Neuman968 closed #1613
  • Sep 20 17:47
    Neuman968 commented #1613
  • Sep 20 17:40
    pakoito commented #1613
  • Sep 20 17:40
    pakoito commented #1613
  • Sep 20 17:20
    Neuman968 commented #1613
  • Sep 20 17:19
    Neuman968 opened #1613
  • Sep 20 11:00
    JYCabello closed #1612
  • Sep 20 11:00
    JYCabello commented #1612
  • Sep 20 10:40
    raulraja commented #1612
  • Sep 20 10:03

    pakoito on ktlint-disable-unit-rule

    (compare)

  • Sep 20 10:03

    pakoito on master

    Upgrade ktlint and disable no-u… (compare)

  • Sep 20 10:03
    pakoito closed #1610
  • Sep 20 09:59
    JYCabello opened #1612
  • Sep 20 09:51
    nomisRev commented #1610
  • Sep 20 09:51
    nomisRev commented #1610
  • Sep 20 09:23
    pakoito commented #1610
  • Sep 19 22:47

    raulraja on rr-meta-prototype-integration

    progress typechecking with the … (compare)

Pedro Silva
@pedromss
Using Jcenter atm

As indicated in the docs (dunno if this section is outdated) with repositories:

repositories {
    jcenter()
    mavenCentral()
    maven("https://dl.bintray.com/arrow-kt/arrow-kt/")
    maven("https://oss.jfrog.org/artifactory/oss-snapshot-local/")
}

Getting:

 > Could not resolve all files for configuration ':compileClasspath'.
   > Could not resolve io.arrow-kt:arrow-core-extensions:0.10.0.
     Required by:
         project :
      > Could not resolve io.arrow-kt:arrow-core-extensions:0.10.0.
         > Could not get resource 'https://oss.jfrog.org/artifactory/oss-snapshot-local/io/arrow-kt/arrow-core-extensions/0.10.0/arrow-core-extensions-0.10.0.pom'.
            > Could not GET 'https://oss.jfrog.org/artifactory/oss-snapshot-local/io/arrow-kt/arrow-core-extensions/0.10.0/arrow-core-extensions-0.10.0.pom'. Received status code 409 from server:
   > Could not resolve io.arrow-kt:arrow-typeclasses:0.10.0.
     Required by:
         project :
      > Could not resolve io.arrow-kt:arrow-typeclasses:0.10.0.
         > Could not get resource 'https://oss.jfrog.org/artifactory/oss-snapshot-local/io/arrow-kt/arrow-typeclasses/0.10.0/arrow-typeclasses-0.10.0.pom'.
            > Could not GET 'https://oss.jfrog.org/artifactory/oss-snapshot-local/io/arrow-kt/arrow-typeclasses/0.10.0/arrow-typeclasses-0.10.0.pom'. Received status code 409 from server:
   > Could not resolve io.arrow-kt:arrow-extras-data:0.10.0.
     Required by:
         project :
      > Could not resolve io.arrow-kt:arrow-extras-data:0.10.0.
         > Could not get resource 'https://oss.jfrog.org/artifactory/oss-snapshot-local/io/arrow-kt/arrow-extras-data/0.10.0/arrow-extras-data-0.10.0.pom'.
            > Could not GET 'https://oss.jfrog.org/artifactory/oss-snapshot-local/io/arrow-kt/arrow-extras-data/0.10.0/arrow-extras-data-0.10.0.pom'. Received status code 409 from server:
   > Could not resolve io.arrow-kt:arrow-extras-extensions:0.10.0.
     Required by:
         project :
      > Could not resolve io.arrow-kt:arrow-extras-extensions:0.10.0.
         > Could not get resource 'https://oss.jfrog.org/artifactory/oss-snapshot-local/io/arrow-kt/arrow-extras-extensions/0.10.0/arrow-extras-extensions-0.10.0.pom'.
            > Could not GET 'https://oss.jfrog.org/artifactory/oss-snapshot-local/io/arrow-kt/arrow-extras-extensions/0.10.0/arrow-extras-extensions-0.10.0.pom'. Received status code 409 from server:
Bob Glamm
@glammr1
right. Artifacts are changed as well. One second
  [ 'core', 'syntax', 'mtl', 'optics', 'fx', 'recursion', 'free', 'aql' ].forEach {
      compile "io.arrow-kt:arrow-${it}:$ARROW_VERSION"
  }
Pedro Silva
@pedromss

Those work. Thank you. fix is still not available. Running ./gradlew clean compileKotlin I now get a compile error:

public inline fun <A, B, C, D, E, F, G, H, I, J> Tuple10Of<???, ???, ???, ???, ???, ???, ???, ???, ???, User> /* = Kind<Kind9<[ERROR : Unknown type parameter 52. Please try recompiling module containing "Class 'arrow.core.Higherkind_arrow_core_Tuple10Kt'"], [ERROR : Unknown type parameter 53. Please try recompiling module containing "Class 'arrow.core.Higherkind_arrow_core_Tuple10Kt'"], [ERROR : Unknown type parameter 54. Please try recompiling module containing "Class 'a

Does this mean anything to you?

I also add kapt("io.arrow-kt:arrow-meta:$arrowVersion") in my dependencies. Did the artifact for this changed as well?
Bob Glamm
@glammr1
I don't use arrow-meta. I know that the system is moving to compiler plugin
Pedro Silva
@pedromss
Ok, nevermind the compiler error, Gradle clean + Organize imports "solved it".
Now I tried to use fix() again and it didn't resolve. Adding the import arrow.core.fix causes the compiler error I mentioned above. Weird
Pedro Silva
@pedromss
Since it isn't really necessary atm, I'll defer this problem to when it becomes a problem. Thanks for the help with the artifacts ;)
Bob Glamm
@glammr1
np. For sure .fix() does not exist on value in your scenario - I've tested against my workspace using 0.10.0
Bob Glamm
@glammr1
The guys in #arrow on the kotlinlang slack should be able to answer the .fix() question for you
Pedro Silva
@pedromss
Waiting on the invite to join : /
Bob Glamm
@glammr1
Unfortunately there is nothing I can do to assist you with that
Pedro Silva
@pedromss

Hey again. After reading the docs I'm trying to make a simple example with arrow where I define a behaviour and can choose a "container" to run that behaviour, i.e. Try, Option, etc...

The TryMonad and the OptionMonad are already supplied by Arrow so that was pretty easy to accomplish.

Now I'm trying to implement monad for the CompletionStage of Java to see if I can have async code without changing the implementation.

Getting stuck on the implementation of the Monad<ForCompletionStage> as the signatures aren't making much sense to me.

class ForCompletionStage private constructor() { companion object }
typealias CompletionStageFor<V> = Kind<ForCompletionStage, V>
data class CompletionStageK<V>(val fut: CompletionStage<V>) : CompletionStageFor<V>
@Suppress("UNCHECKED_CAST", "NOTHING_TO_INLINE")
inline fun <A> Kind<ForCompletionStage, A>.fix(): CompletionStageK<A> = this as CompletionStageK<A>

interface CompletionStageMonad : Monad<ForCompletionStage> {

    companion object {}

    override fun <A> just(a: A): Kind<ForCompletionStage, A> {
        return CompletionStageK(CompletableFuture.completedFuture(a))
    }

    override fun <A, B> Kind<ForCompletionStage, A>.flatMap(f: (A) -> Kind<ForCompletionStage, B>): Kind<ForCompletionStage, A> {
        return ... // unable to proceed here
    }
}

I would expect the flatMap signature to be override fun <A, B> Kind<ForCompletionStage, A>.flatMap(f: (A) -> Kind<ForCompletionStage, B>): CompletionStage<A> and not have a Kind<..., ... > as a return type.

Looking ath the Monad tutorial on the arrow docs the Monad.flatMap does not have a Kind as a return.

Can someone enlighten me on how to implement this Monad?

Pedro Silva
@pedromss
The working example I got for Try and Option and where I'm trying to use a CompletionStage is this:
import arrow.Kind
import arrow.core.ForOption
import arrow.core.extensions.OptionMonad
import arrow.typeclasses.Applicative
import arrow.typeclasses.Monad

interface Source<F> : Applicative<F> {
    fun findOne(key: Int): Kind<F, User>
}
interface MemSource<F> : Source<F> {

    val db: MutableMap<Int, User>

    override fun findOne(key: Int): Kind<F, User> {
        return just(db[key]!!)
    }
}
interface Printer<F> : Monad<F> {
    fun Kind<F, User>.print(): Kind<F, User> {
        this.map {
            println("PRINTER:::::User is: $it")
            it
        }
        return this
    }
}
interface Fetcher<F> : Source<F>, Printer<F> {
    fun fetchUser(id: Int): Kind<F, User> {
        return findOne(id).print()
    }
}
fun main() {
    val x = object : OptionMonad, MemSource<ForOption>, Fetcher<ForOption> {
        override val db: MutableMap<Int, User> = mutableMapOf(1 to User(1))
    }
    println("From main: ${x.fetchUser(1)}")
}
Pedro Silva
@pedromss
Now I'm wondering if we can have abstractions that work both for synchronous and asynchrous code... Can we? Or are we limited to synchrous behaviour with multiple implementation OR async behaviour with different underlying contexts (i.e. observables, coroutines, futures, etc..)
Bob Glamm
@glammr1
There's a different lower constraint for async - try using Async<F> instead of Monad<F> as your lower bound
You'll need to construct with IO.async() to satisfy Async<F> but the typeclass inheritance enables usage of the combinators along the Monad hierarchy
Pedro Silva
@pedromss
Will Async<F> work with TryMonad?
Bob Glamm
@glammr1
IIRC Try isn't great. I think Async extends MonadThrow or MonadDefer which has the catch/handleError* combinators instead
e.g. something like
    fun connection(usage: suspend MonadThrowSyntax<F>.(Connection) -> Unit): Kind<F, Unit> =
            fx.monadThrow { DriverManager.getConnection(dbUrl, username, password) }.bracket(
                    { conn -> fx.monadThrow { conn.close() } },
                    { conn -> fx.monadThrow { usage(conn) } }
            )
which isn't Async, necessarily, but Async contains monadThrow
Bob Glamm
@glammr1
and monadThrow handles exceptions
Paco
@pakoito
@pedromss the reason why fix didn't work on that first example is because fix is specialized for a single value, not for all F generic values
you were trying to get a monomorphic value, like option, on a generic context that's supposed to work for all of them
so how would you work with it? that's what typeclasses are for! because it's an Applicative you have map, ap and other helper functions
you want more functions? you need to be a typeclass higher on the hierarchy
that, for example
donkeylo
@donkeylo
I am developing an app which involves multi-step calculation, and I am thinking about some sort of audit trail that enables myself to trace the root cause easily if there are any errors. For each calculation step what I need is a brief description of the step, the inputs and outputs of the step, and also from which previous step the inputs are generated. I am new to functional programming and thinking Monad writer might be helpful, but I am unable to find any docs about Monad writer. Could someone please shed some light on it? Thanks
Bob Glamm
@glammr1

I've been told that with interface composition a writer is unnecessary, e.g.:

interface Logger<F>: Monad<F> {
   ... logging ops over F go here ...
}
interface Computation<F>: Async<F>, Logger<F> /* or whatever level of effect you require */ {
  ... computation ops here, using combinators from Logger<F>
}

then if you create a Logger you can easily create a Computation by delegation

The other option is full reification over a free algebra (at least I think those are the right words) where constructors are used to describe the computation that will occur, then the interpreter used by the free algebra to perform the reduction can examine the constructors and perform both the tracing and the computation based on the description. I am much less familiar with that method, although it is possible to make it work.
Paco
@pakoito
@donkeylo I wouldn't go as far as using a writer. For now just pass a function suspend (String) -> Unit as a parameter and execute it where necessary
if at some point it becomes unbearable to pass this function around everywhere, because there is a lot of where to every, then consider a rewrite to MonadWriter
Tolegen Izbassar
@t-izbassar

Hello, I'm using Arrow in my Kotlin backend project. I have repositories like this:

interface UserRepository {
  fun user(username: String): Try<Option<User>>
}

Now I want to go step further and abstract from concrete Try type with returning Kind<F, Option<User>> instead. I was able to do it with this code:

interface UserRepository<F> {
  fun user(username: String): Kind<F, Option<User>>
}

class IdRepository : UserRepository<ForId> {
  fun user(username: String): ForId<Option<User>> =
    if (username == "known") Id.just(Some(User()))
    else Id.just(None)

But now I'm struggling to use it. Suppose I have some service that depends on it:

class UserService<F>(ME: MonadError<F, Throwable>, repo: UserRepository<F>) : MonadError<F, Throwable> by ME {
  fun someOperations(username: String) : Kind<F, User> = bindingCatch {
    val (user) = repo.user(username)
    user.fold({ // create user }, { // return user })
}

I'm trying to follow the documentation on dependency injenction but can't understand how to achieve this.

I don't get how we can tall that F has to be a Monad so that it can be used in bindingCatch comprehension block. Kotlin says it can't infer type on line repo.user call and I kinda agree with it)
Paco
@pakoito
I'd suggest changing to 0.10 first, move to fx
MonadError<F, Throwable> by ME opens a series of extension functions parametrized for F, so that's how you know it's a monad
insted of F extends Monad you say Monad is parametrized to F and Monad is bound to this in UserService
now, on the type inference problem
use ! or .bind() instead of destrutcturing
we're removing it precisey because it's ambiguous sometimes
val user = repo.user(username).bind()
if you need to debug it further, hint the type
val user: Kind<F, Option<User>> = repo.user(username).bind()
and see what the compiler complains about
Tolegen Izbassar
@t-izbassar
thanks, now I get it. I was able to achieve it, now on my way to replace Try with IO.
Tolegen Izbassar
@t-izbassar