> the result is of type [()] but for a cartesian n-product, you would like [[a]]
On Mon, Dec 24, 2012 at 8:01 AM, Jay Sulzberger <jays@panix.com> wrote:Well the type of the first response is a dead give-away : the result
>
> > 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.
>
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@haskell.org
http://www.haskell.org/mailman/listinfo/beginners