Do any conversions exist to treat a Box[_] as an Either[Option[_],Exception] or as an Option[_]? Are there any helper functions that lift could benefit from by having these?
Also, anytime I see the line "I leave this as an excercise to the reader" I feel like I'm being lectured :) On Jan 6, 2009, at 7:38 PM, "Jorge Ortiz" <[email protected]> wrote: > For most people, "is" does not always and exclusively mean "bi- > implication". You are free to think this way, if you choose, but > please don't impose your Language Police on us. > > --j > > On Tue, Jan 6, 2009 at 5:49 PM, Tony Morris <[email protected]> > wrote: > > When talking about data types "is" means "is congruent to" or "is > isomorphic to". You are not free to use "is" arbitrarily, since if you > are then Can "is" anything I want it to be. > Since equivalence can be broken into an implication both ways e.g. A > -> B and B -> A then it is quite easy to test if "Can is an Option". > > def f[A](o: Option[A]): Can[A] // this should be total and bijective > def g[A](c: Can[A]): Option[A] // this should be total and bijective > > The use of => in function signatures means logical implication. Does > Can imply Option? Yes (you can complete the g function). Does Option > imply Can? No (you cannot complete the f function). Therefore, Can is > not an Option. It was not even close (lack of totality in this test is > catastrophic). > > If you want to try to save this notion of "Well Can is a something", > then I have already pointed out a suggestion. Try to think of others, > but do not say that Can is an Option - it is not, not even close. Poor > Oliver was all confuzzled when he popped this one to me the other day. > > -- > Tony Morris > http://tmorris.net/ > > S, K and I ought to be enough for anybody. > > > Jorge Ortiz wrote: > > It depends on what the meaning of "is" is. > > > > If Option were not sealed, "Can" could be "implemented" as an > > Option... by adding Failure and Empty as subclasses of None. In > > this (OO) sense, a Can is an option. > > > > In the algebraic sense, then you're probably right that a Can is > > not an Option. > > > > --j > > > > On Tue, Jan 6, 2009 at 5:23 PM, Tony Morris <[email protected] > > <mailto:[email protected]>> wrote: > > > > > > No this is a mistake. Can is not an Option. Indeed it is (almost) > > impossible to write Can using Option (if you are familiar with > > Peano Arithmetic you will understand the need to qualify with > > almost). There is an arrow from forall A. Can[A] to Option[A] but > > not from forall A. Option[A] to Can[A] (easily) - try it for > > yourself. To suggest that Can is an Option (or "an Option with more > > features" or "an Either") is a mistake of misintegration (Peikoff > > DIM Hypothesis). Indeed the Can algebra has nothing to do with > > Option (except for the aforementioned function). There is no > > isomorphism between Can and Option - they are not the same, not > > even close. > > > > Here is a bit of code for fun. Note the bijective function using > > Either alone: > > > > sealed trait T[+A] { val e: Either[(String, T[Throwable], > > List[(String, Throwable)], Either[A, Unit]] > > > > // bijection to e val c: Can[A] = e match { case Left(m, e, c) => > > Failure(m, e, // Can makes the mistake of using a data constructor > > as a type. // Unfortunately Scala permits this. c map toFailure) > > case Right(e) => e match { case Left(a) => Full(a) case Right(_) => > > Empty } } } > > > > object T { // construct with Either or Can } > > > > -- Tony Morris http://tmorris.net/ > > > > S, K and I ought to be enough for anybody. > > > > > > David Pollak wrote: > >> It's an Option. > >> > >> It contains a value or it doesn't. In the case that it does not > >> contain a value, it may contain out of band information. This is > >> not any different from None which contains information. It > >> contains the information that it lacks information. > >> > >> Sure, you can write Option[T] as Either[T, Nothing], but the > >> value of only having on type is lost. > >> > >> On Tue, Jan 6, 2009 at 2:59 PM, Tony Morris > > <[email protected] <mailto:[email protected]> > >> <mailto:[email protected] <mailto:[email protected]>>> > > wrote: > >> > >> > >> Right, that's what Oliver said and I was reinforcing it with > >> deductive reasoning. It is also not Option. It is something else > >> altogether. Nevertheless, an isomorphism can easily be written > > with > >> Either alone (ignoring bottoms). So in some loose sense "it is an > >> Either". > >> > >> -- Tony Morris http://tmorris.net/ > >> > >> S, K and I ought to be enough for anybody. > >> > >> > >> David Pollak wrote: > >>> Tony, > >>> > >>> Can (now Box) is not an Either. > >>> > >>> David > >>> > >>> On Tue, Jan 6, 2009 at 2:37 PM, Tony Morris > >> <[email protected] <mailto:[email protected]> > > <mailto:[email protected] <mailto:[email protected]>> > >>> <mailto:[email protected] <mailto:[email protected]> > > <mailto:[email protected] <mailto:[email protected]>>>> > >> wrote: > >>> > >>> > >>> Can is not an Option and to call it so in any way is an error > >>> of misintegration. Indeed it would be an error to "replace > >>> Option > >> with > >>> Can" - they are completely different algebras. Either is kinded > >>> * -> * -> * so cannot possible be isomorphic and cannot > >>> possibly > >> have > >>> map, flatMap etc (though it can have a bifunctor map being > >>> covariant in both type arguments). However, > >>> Either.LeftProjection and Either.RightProjection are kinded * > >>> -> * and are both > >> covariant > >>> functors and monads, hence map, flatMap etc. are available. > >>> e.g. for(x <- either.left) ... is valid, try it. > >>> > >>> Of mild interest, it is possible to construct an isomorphism > >> to Can > >>> using both Either and Option. Indeed, it is possible to > >>> construct an isomorphism to Option using Either e.g. forall A. > >>> Option[A] ≡ Either [Unit, A] so it is possible using Either > >>> alone. I'll leave both as reader exercises. > >>> > >>> > >>> On Dec 21 2008, 5:15 am, Oliver Lambert <[email protected] > > <mailto:[email protected]> > >> <mailto:[email protected] <mailto:[email protected]>> > >>> <mailto:[email protected] <mailto:[email protected]> > > <mailto:[email protected] <mailto:[email protected]>>>> wrote: > >>>> Ok so Can is not either an Either or an Option, its a Can. I > >>> kind of > >>>> wondered when I first used Can, and it was described as an > >>> enhanced > >>>> Option, why it wasn't called something like Option+ with > >>> None, Some > >>>> and Failure. > >>>> > >>>> On 21/12/2008, at 5:47 AM, David Pollak wrote: > >>>> > >>>>> Can has map, flatMap, filter etc. So it can be used in a > >>>>> for comphrension. I don't believe Either has those methods. > >>>>> > >>> Further, > >>>>> Can has a bunch of helpers to turn Empty into Failure > >>>> > >>>>> On Dec 20, 2008 10:33 AM, "Oliver Lambert" > > <[email protected] <mailto:[email protected]> > >> <mailto:[email protected] <mailto:[email protected]>> > >>> <mailto:[email protected] <mailto:[email protected]> > > <mailto:[email protected] <mailto:[email protected]>>>> wrote: > >>>> > >>>>> Is Can a little less like Option and more like > >>>>> scala.Either, > >>> where > >>>>> the left side is used to indicate failure? On 21/12/2008, > >>>>> at 1:43 AM, David Pollak wrote: > Folks, > > > >>> Over the > >>>>> year that Lift has had Can[T... > >>> > >>> > >>> > >>> > >>> > >>> -- Lift, the simply functional web framework http://liftweb.net > >>> Collaborative Task Management http://much4.us Follow me: > >>> http://twitter.com/dpp Git some: http://github.com/dpp > >>> > >>>> > >> > >> > >> > >> > >> > >> > >> > >> > >> -- Lift, the simply functional web framework http://liftweb.net > >> Collaborative Task Management http://much4.us Follow me: > >> http://twitter.com/dpp Git some: http://github.com/dpp > >> > >>> > > > > > > > > > > > > > > > > > > > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ > You received this message because you are subscribed to the Google > Groups "Lift" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/liftweb?hl=en > -~----------~----~----~----~------~----~------ > fi0tfi0tLTxicj4KPGJyPgo=20gPGJyPiBGb3IgbW9yZSBvcHRpb25zLCB2 isit > this group at http://groups.google.com/group/liftweb?hl=en > -~----------~----~----~----~------~----~------ > fi0tfi0tLTxicj4KPGJyPgo=go= --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~----------~----~----~----~------~----~------~--~---
