A Tour of Go in Haskell

GitHub Language
Range and Close

Although Haskell channels do not range or close operations like Go, those can easily be implemented if needed.

The range clause on a for statement in Go is useful to iterate channel values like a collection. Because getChanContents :: Chan a -> IO [a] converts channel to list, it works similar to range.

A built-in function close of Go marks that no more values will be sent to a channel. Maybe can be used to imitate close. We send Nothing as the last value. Note that this is just a simple solution; it does not cause errors like Go if extra values are sent to a closed channel.

By the way, the sample code on the right side can be implemented using Haskells list. Refer to the list version below.

< 4 / 11 >