[Haskell-beginners] Why does sequence (map print [1, 2, 3, 4, 5]) produce [(), (), (), (), ()] at the end?
toad3k at gmail.com
Wed Feb 3 13:11:34 UTC 2016
In ghci, any statement that returns Show a => IO a (that is IO a where the
a is showable) will be run in IO and the result a will be shown once it
finishes. If a is not showable it will simply run the IO action, but not
show the result.
> :t sequence (map print [1,2,3])
sequence (map print [1,2,3]) :: IO [()]
> :i Show
instance Show a => Show [a] -- Defined in ‘GHC.Show’
instance Show () -- Defined in ‘GHC.Show’
On Wed, Feb 3, 2016 at 5:35 AM, Olumide <50295 at web.de> wrote:
> On 01/02/2016 17:39, David McBride wrote:
>> Note that it has not actually printed them out.
> I hope you don't mind me asking but why then does sequence (map print
> [1,2,3] ) return the numbers 1, 2, 3 (albeit followed by [(),(),()]).
> It merely has an array of as yet unexecuted actions. To print them
>> you'd go like sequence (map print) [1,2,3] ...
> Erm ... sequence (map print) [1,2,3] returns an error.
> - Olumide
> Beginners mailing list
> Beginners at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners