Comments (20)
Another extension to Monoid I was playing around with:
// This protocol allows you to call plus directly on an instance.
protocol Addable {
func plus(x: Self) -> Self
}
// And an example of how to implement Addable for some type.
// This feels repetitive... there's certainly some better way to write this thing.
extension Int: Addable {
var monoid: IntMonoid { return IntMonoid() }
func plus(x: Int) -> Int {
return monoid.plus(self, x);
}
}
Let me know!
from swiftz.
@sritchie if you renamed your Injection stuff to "read and show" or "printable" and "readable" yes. They're not bijections.
@sritchie addable is just Semigroup. We have that merged in already https://github.com/maxpow4h/swiftz/blob/master/swiftz/Semigroup.swift
I'm pretty sure we've got a lot of semigroup / monoid stuff,but having decent counting structures could be cool. though it might be a good idea to be conservative on how much gets in, i'm not sure how often ios/os x applications need server class approximate counting data structures.
I assume you mean the stuff in https://github.com/twitter/algebird/tree/develop/algebird-core/src/main/scala/com/twitter/algebird ?
from swiftz.
@sritchie Hey!
I am absolutely taking any PRs of associative data structures, like in Algebird.
As @cartazio mentioned, I have added a couple of instances semigroup and monoid. They are here. https://github.com/maxpow4h/swiftz/blob/27031fea2ce7496715e4d5345149fd8f156b24e5/swiftzTests/swiftzTests.swift#L268-L277
More useful instances would be very good! I just added those ~3 to define a Monoid
type that can satisfy lots of different problems. (The technique I use in Monoid stops you from needing an Int, Int8, etc. version of everything).
As for Bijection / Injection, they would be very useful! My only ask, is if you could name them Isomorphism
and Prism
respectively.
Thanks!
from swiftz.
@maxpow4h I was not aware that prisms were injections?
[Sorry folks, pressed the wrong button there!]
from swiftz.
@maxpow4h oh, those are Lens Isos? I thought it was A->String and String->A only, rather than proper Isos ala lens
from swiftz.
@jonsterling That protocol is a Simple Prism. I.e. Prism s s a a
.
But I don't think we can support polymorphic lenses any time soon ;)
from swiftz.
ohh, yeah, they are Isos and prisms, my bad :)
from swiftz.
Oh man, somehow i wasn't getting updates for this thread. Glad I checked in. Let me read up, one sec.
from swiftz.
@cartazio As the author of that library, I COMPLETELY understand, and will for all time, that those examples are not Bijections. That doesn't mean that bijection isn't a useful typeclass. (The Bijection library is mostly full of injections,btw.)
@maxpow4h about the Monoid and Semigroup, I did a bit more playing around and came up with this:
https://gist.github.com/sritchie/27bdf9329027d5cdf02e#file-algebra-swift-L70
Using "Self" removes the need for the duplication in the type parameter. You also don't have to supply the monoid or semigroup instance as the first argument anymore.
Happy to make that change too and update the tests if you're interested.
from swiftz.
@cartazio that's correct about those algebird data structures, I'd love to get some of those in.
from swiftz.
@maxpow4h about the Injection as a Prism, I'll have to read up.
from swiftz.
@sritchie the idea is the a-> Either a b is an injection (aka prism)
because you can't write a safe Either a b -> a
from swiftz.
@cartazio yeah, I get that (the injection vs bijection thing). It's a prism vs an injection because of the extra type parameter on Either, correct?
from swiftz.
http://hackage.haskell.org/package/lens-4.2/docs/Control-Lens-Prism.html#g:2 shows some machinery for prisms
replicating it inline
type Prism s t a b = forall p f. (Choice p, Applicative f) => p a (f b) -> p s (f t)
-- some ways to construct prisms
prism :: (b -> t) -> (s -> Either t a) -> Prism s t a b
--- a way to construct a simple prism
prism' :: (b -> s) -> (s -> Maybe a) -> Prism s s a b
from swiftz.
so in the really simple case we could have
prism' :: (a-> s) -> (s -> Maybe a) -> Prism s s a a
where s= Either a b
might be one choice in s
(this is just a teeny piece of the awesome generality of lens (which I myself am still learning))
so a simple prism might be formed out of
foo :: a-> Either a b
bar :: Either a b -> Maybe a
from swiftz.
Yeah, so #34 has convinced me Control.Lens
is not useful in Swift, but Data.Lens
is.
So a "Prism", which would be a Function, becomes a class.
protocol Prism {
let apply: A -> B
let invert: B -> A?
}
exactly the same as the --Bijection-- Injection class definition.
Edited that, accidentally hit ctrl enter
from swiftz.
We are talking about the same things, I would just prefer to use the Lens version of terminology
from swiftz.
'Bijection class definition.' dont you mean injection?
from swiftz.
Yes.
from swiftz.
Advancement of the Data.Lens stuff makes this issue a bit irrelevant at the moment. Closing.
from swiftz.
Related Issues (20)
- Split JSON Out of Swiftz HOT 22
- Algebraic data types HOT 4
- Operators documentation HOT 2
- Any plans to add Reader monad? HOT 9
- Swift.match() instead of a computed properties? HOT 4
- support the swift package manager HOT 5
- Breaks on Swift 2.2 because it relies on non-existing private protocol `_Strideable` HOT 1
- 0.5.0 not found on cocoapods HOT 1
- Consider `Array.groupBy` to use adjacent element predicate rather than span. HOT 3
- Will CocoaPods be supported? HOT 5
- Getting a `the package has an unsupported layout` error when `swift build` HOT 6
- Build failure under Xcode 8.2 HOT 2
- When will there a new release that fixes the 0.6.1 compilation error? HOT 1
- Cocoapods: support for newest versions HOT 2
- 114 warnings Xcode 9.1 HOT 1
- Swift 4.0.2 support HOT 1
- Swiftz source missing from Pods HOT 7
- Swiftz-Swift.h is not produced in Headers folder of Framework
- Swift 5 HOT 1
- Still Maintained? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swiftz.