truizlop on utilities
truizlop on master
Miscellaneous utilities (#459) … (compare)
truizlop on utilities
Add docs (compare)
truizlop on utilities
Fix wrong documentation Add instances of Semigroup and … Add utility to Kleisli and 2 more (compare)
miguelangel-dev on calvellido-patch-1
miguelangel-dev on master
Fix bad space char at docs (#45… (compare)
/*: --- */
in an Xcode playground supports Markdown, and that is what we use to render the docs
Documentation.xcworkspace
, and adding a new page to a section is just adding a page to the corresponding playground.
nef
as well in order to get familiar with it
nef
given in AltConf - altconf.miguelangel.me
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
NaturalSubclass.swift
, then Natural.swift
, then Co.swift
there
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
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.
Reader<D, A>
is like a plain function (D) -> A
ask
to get a Reader<D, D>
IO
:
protocol Storage {
func save(_ user: User) -> IO<Never, Bool>
}
protocol API {
func fetch(byId: Int) -> IO<Never, User>
}
struct Env {
let database: Storage
let api: API
}
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>
"
Env
for production, or another one for testing:
let result = try! cacheUser(byId: 1234)
.invoke(Env(database: StorageImpl(),
api: APIImpl()))^
.unsafePerformIO()