Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Oct 09 2019 10:41
    iboss-ptk synchronize #460
  • Oct 09 2019 10:21
    iboss-ptk edited #460
  • Oct 09 2019 10:21
    iboss-ptk edited #460
  • Oct 09 2019 10:20
    iboss-ptk opened #460
  • Oct 09 2019 09:58

    truizlop on utilities

    (compare)

  • Oct 09 2019 09:58

    truizlop on master

    Miscellaneous utilities (#459) … (compare)

  • Oct 09 2019 09:58
    truizlop closed #459
  • Oct 09 2019 07:53
    truizlop review_requested #459
  • Oct 09 2019 07:53
    truizlop review_requested #459
  • Oct 09 2019 07:53
    truizlop opened #459
  • Oct 09 2019 07:53

    truizlop on utilities

    Add docs (compare)

  • Oct 09 2019 07:52

    truizlop on utilities

    Fix wrong documentation Add instances of Semigroup and … Add utility to Kleisli and 2 more (compare)

  • Oct 09 2019 07:03
    truizlop commented #448
  • Oct 09 2019 01:34
    iboss-ptk commented #448
  • Oct 09 2019 01:28
    iboss-ptk commented #448
  • Oct 08 2019 10:42

    miguelangel-dev on calvellido-patch-1

    (compare)

  • Oct 08 2019 10:42

    miguelangel-dev on master

    Fix bad space char at docs (#45… (compare)

  • Oct 08 2019 10:42
    miguelangel-dev closed #458
  • Oct 08 2019 10:42
    miguelangel-dev commented #458
  • Oct 08 2019 10:39
    calvellido edited #458
even an example, you can use this talk about nef given in AltConf - altconf.miguelangel.me
balrajOla
@balrajOla
@miguelangel-dev sure I will refer this and thanks for this info.
Tomás Ruiz-López
@truizlop
I have updated the contribution guidelines to include all you need to know to set up the environment and start adding content, and test it locally as well: https://github.com/bow-swift/bow/blob/master/CONTRIBUTING.md#documentation
Brandon Kase
@bkase

Hello! I've been playing with Bow for a bit, and I'm trying to figure out how to properly emulate rank2 type polymorphism https://en.wikipedia.org/wiki/Parametric_polymorphism .

I saw Bow supports the Day convolution which typically needs rank2 type support. In the Bow presentation, Day is implemented using a subclass to "hide the existential", and it seems to work there, but it doesn't generalize to other rank2 data types: There isn't a way to "choose the type parameter" as far as I can tell with the subclass approach.

It's not super ergonomic, but I think I managed to find an approach using protocols that does support rank2 types properly.

I think the simplest example for this is a natural transformation, below it's implemented with the subclass approach (which crashes as written) and my protocol approach.

Unfortunately, the problem is the protocol approach is that it causes this extra type parameter to float around which (1) annoying to deal with and (2) makes it so we can't implement the existing typeclasses (see my attempt at implementing Co)

https://gist.github.com/bkase/86b40d80f3e44594917fd39b8fe1fe02

See gist for the code snippets ^^
Any help would be appreciated! Thanks!
Read NaturalSubclass.swift, then Natural.swift, then Co.swift there
Brandon Kase
@bkase
maybe I just don't understand the stepDay part? I imagine it was ported from here: https://github.com/arrow-kt/arrow/blob/master/modules/ui/arrow-ui-data/src/main/kotlin/arrow/ui/Day.kt#L14
Tomás Ruiz-López
@truizlop
Hi Brandon, I’ll take a look at your approach tomorrow and we can discuss it further.
Brandon Kase
@bkase
Thanks!
Tomás Ruiz-López
@truizlop
Hi Brandon, I have been taking a look at your code. I think it is a clever approach. As you have guessed, the implementation of Day is incomplete since there are things that I could not implement for the same reason you state in your gist. The way it works in Kotlin is because they can provide anonymous implementations of interfaces inside methods that capture all type arguments present in the scope; that way, they don't need to carry the extra witness in the type signature as you had to do.
That is the problem we are also having when you try to implement Functor for Co. As per its definition, we can only change A to B, but in this case we would also need to transform the existential witness. I am afraid the current encoding we have to simulate HKTs does not allow to do this, or at least I cannot think of a way to do it at the moment.
Brandon Kase
@bkase
Dang that’s unfortunate. I’m planning on going to a local Swift meetup next week where I can get more eyes on it, maybe someone will come up with something
Tomás Ruiz-López
@truizlop
That would be awesome. Keep us posted if you have new findings. I’ll try to rethink the problem and see if I can come up with an alternative.
Tomás Ruiz-López
@truizlop
Hi @balrajOla, did you try to set up the environment? Anything we can help you with?
balrajOla
@balrajOla
Hi @truizlop I am going through arrow kit to understand all these functional concepts as I new to Functional world. I am also trying to understand how to write the documentation so as to showcase the advantages of using these construct. This might take some time. In the meantime i have already setup the project and checked on how to write the documentation. If you can provide me some content to refer that might be of help.
Tomás Ruiz-López
@truizlop
Nice to hear that. Feel free to ask us if you have any questions
Tomás Ruiz-López
@truizlop
Although Twitter seems to be down at the moment
Sébastien Drode
@Dragna
Hi everyone, I've been away from my tests on Bow for some time, but I'm back 🙂 . I would like to play with reader, writer and state monad, but I don't quite understand how to use them 😓. How should I instantiate a Reader Monad with a value that would represent my environment ? and after that, how can I access it ?
Tomás Ruiz-López
@truizlop
Welcome back Sébastien!
ok so Reader<D, A> is like a plain function (D) -> A
you can usually start with calling the static method ask to get a Reader<D, D>
and map over the right argument
Tomás Ruiz-López
@truizlop
if you have an effect F, you typically need to use ReaderT<F, D, A>, which is (D) -> F<A> (namely, (D) -> Kind<F, A>
so, an example using IO:
Tomás Ruiz-López
@truizlop
Let's say I have these two protocols describing the operations I can do for network and database:
protocol Storage {
    func save(_ user: User) -> IO<Never, Bool>
}

protocol API {
    func fetch(byId: Int) -> IO<Never, User>
}
I can create an structure with the dependencies I am going to need
struct Env {
    let database: Storage
    let api: API
}
Then, I can write a function with the following signature:
func cacheUser(byId userId: Int) -> ReaderT<IOPartial<Never>, Env, Bool> which means: "Give me a user ID, and I will return a Reader that, when provided an Env will have all it needs to produce IO<Never, Bool>"
Tomás Ruiz-López
@truizlop
func cacheUser(byId userId: Int) -> ReaderT<IOPartial<Never>, Env, Bool> {
    return ReaderT<IOPartial<Never>, Env, Env>.ask()
        .map { env in env.api.fetch(byId: userId) }
        .flatMap { io in
            ReaderT { env in io.flatMap { user in env.database.save(user) } }
        }^
}
Finally, you can run this function by passing an Env for production, or another one for testing:
let result = try! cacheUser(byId: 1234)
    .invoke(Env(database: StorageImpl(),
                api: APIImpl()))^
    .unsafePerformIO()
Sébastien Drode
@Dragna
ok I wasn't reasoning about that the right way
I was Thinking of the reader as a Big environment that I had to pass around to my functions
Thank you for your help, I will play with that and see what I can do with it :)
Tomás Ruiz-López
@truizlop
for Writer and State, is quite similar but considering that you can append things to the Env (Writer), or set/get things in the Env (State)
Sébastien Drode
@Dragna
so If I wanted a structure that act like an elm component, State would be the best choice ? something that take an action coming from the UI and run it against the current state to return a new state
Tomás Ruiz-López
@truizlop
most likely
for an example of State, I have a sample in a repo
let me check
Sébastien Drode
@Dragna
and I saw on the last commit that you have a new syntax for monad comprehensions, it seems better than the old one :)
Tomás Ruiz-López
@truizlop
yes, that will come in the next version and I think it will make things a looot easier to write
from that line on, you can see how I use State to track the inputs and outputs to see the Console has the right interactions
the repo might be outdated though, I'll try to update it when I'm back from vacation
Sébastien Drode
@Dragna
ok thank you for your help, I will play with all the informations you gave me :)
Tomás Ruiz-López
@truizlop
You’re welcome! Feel free to ask if you find any issue
Thang Mai
@mxth
 let o1 = Option.some(1)
 let o2 = Option.some(2)
 let o3 = Option.map(o1, o2, { $0 + $1 })
I couldn't make it work, getting Cannot convert value of type 'Option<Int>' to expected argument type 'Kind<ForOption, _>'. I'm new to swift & bow, please help.