Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you turn a Haskell list into a series of do instructions?

Can you create a list of functions and then execute them sequentially, perhaps passing them into do notation?

I'm currently doing this by mapping over a list of data and am wondering if I can call somehow pass the result as a series of sequential calls?

like image 600
toofarsideways Avatar asked Mar 10 '10 19:03

toofarsideways


People also ask

What does list do in Haskell?

In Haskell list is used to store the elements, and these elements are homogenous in nature which simply means only one type. Inside the list, we can store the list of elements that are of the same type. we can store any data type inside the list.

How do list comprehensions work in Haskell?

List comprehension in Haskell is a way to produce the list of new elements from the generator we have passed inside it. Also for the generator values, we can apply the Haskell functions to modify it later. This list comprehension is very y easy to use and handle for developers and beginners as well.

How do I convert a list to a tuple Haskell?

In a general way, you can't. Each size of tuple is a distinct type, whereas lists of any length are a single type. Thus, there's no good way to write a function that takes a list and returns a tuple of the same length--it wouldn't have a well-defined return type.

Are lists in Haskell linked lists?

Second, lists in Haskell are (internally) implemented as linked lists. This is different from many other languages, where the word "list" and "array" is used interchangably.


1 Answers

Something like this?

sequence [putStrLn "Hello", putStrLn "World"]
like image 200
jkff Avatar answered Sep 27 '22 18:09

jkff