[Haskell-beginners] Cartesian Product in Standard Haskell Libraries
Kim-Ee Yeoh
ky3 at atamo.com
Mon Dec 24 13:08:51 CET 2012
> the result is of type [()] but for a cartesian n-product, you would like
[[a]]
Right. So what we have here is a product over a count of 0 sets, which is
isomorphic to the function space that has the null set as domain. The
latter has exactly one element: the trivial function.
My apologies for misreading what OP wrote:
> This looks to me to be a violation of the rule that the Cartesian
> product of an empty list of lists is a list with one element in
> it.
I thought he meant something along the lines of sequence ["","x"].
-- Kim-Ee
On Mon, Dec 24, 2012 at 4:42 PM, Chaddaï Fouché <chaddai.fouche at gmail.com>wrote:
> On Mon, Dec 24, 2012 at 8:01 AM, Jay Sulzberger <jays at panix.com> wrote:
> >
> > > sequence []
> > []
> > it :: [()]
> >
> > This looks to me to be a violation of the rule that the Cartesian
> > product of an empty list of lists is a list with one element in
> > it. It looks to be a violation because "[]" looks like a name
> > for an empty list. But we also have
> >
> > > length (sequence [])
> > 1
> > it :: Int
> >
> > which almost reassures me.
> >
>
> Well the type of the first response is a dead give-away : the result
> is of type [()] but for a cartesian n-product, you would like [[a]]
> (with a maybe instantiated to a concrete type) ...
> What's happening here is that sequence is not "the cartesian
> n-product" in general, it is only that in the list monad but in
> "sequence []" there's nothing to indicate that we're in the list
> monad, so GHC default to the IO monad and unit () so sequence has the
> type "[IO ()] -> IO [()]" and there's no IO action in the list
> parameter, so there's nothing in the result list.
>
> Try :
> > sequence [] :: [[Int]]
> and you should be reassured.
>
> --
> Jedaï
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20121224/28981c7c/attachment.htm>
More information about the Beginners
mailing list