On Mon, Feb 9, 2015 at 5:29 PM, Jonathan S. Shapiro <[email protected]> wrote:
> On Mon, Feb 9, 2015 at 3:22 PM, Geoffrey Irving <[email protected]> wrote:
>>
>>
>> Scala (and I believe Fortress) solve this by mechanically translating
>> comprehensions into iterated calls to flatMap / map / filter, and then
>> using whatever result types flatMap produces.  E.g.,
>>
>>     zs = [ (x,y) | x <- xs; y <- ys ]
>>
>> would turn into
>>
>>     zs = concatMap (x -> map (y -> (x,y)) ys) xs
>>
>> If concatMap can generate a certain collection type, so can
>> comprehensions.  If the user wants to make a particular container use
>> extremely fancy ad-hoc techniques to be flexible, they can choose to
>> do that for the particular concatMap overloads.
>
> That makes sense. And given the type class approach that Keean and I seem to
> be agreeing on, I know how to think about that. It seems a little odd to me
> that [ expr | generator ] is a syntactic construct unrelated to lists, but
> that's *all* it is - a bit odd.

Scala uses unrelated syntax:

    for (x <- xs; y <- ys) yield (x,y)

Not sure what Fortress did.  I agree that using list syntax for
general monadic comprehensions would be confusing.  I'm not
particularly enamored with Scala's syntax.

> The consequence that I would pragmatically expect is that you'd end up with
> the type of the result set being underspecified in many cases, leading to a
> need for annotations to ensure that the result set type actually
> concretizes. The success of type classes at abstracting the type ends up
> leaving your waist size so abstract that your pants fall down. :-)
>
>>
>> The place where this breaks down in scala is different container
>> types.  E.g., you like a comprehension involving a list and an option
>> to produce a list (probably), but it is either a compile error or
>> something useless.
>
>
> That seems odd. I'm not sure I see how that would happen...

It just be me, but I routinely find myself wanting this overload:

    concatMap :: (b -> Maybe c) -> [a] -> [c]

I.e., a concatMap overload that mixes two different monads together.
It only makes sense for certain monads (Maybe injects into List), but
it seems to come up with some frequency.

Geoffrey
_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev

Reply via email to