Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pattern Matching and List Comprehension in List of Tuples

type a = [(Int,Int,Int,Int)]

fun:: a -> Int
func [a,b,c,d] = ?

I have a list of tuples like this what i required is to apply list comprehensions or pattern matching .. example taking sum or filter only divide 2 numbers ... i just want a start how to access values and or a list comprehension to this List of Tuples

like image 537
Sudantha Avatar asked Dec 09 '25 09:12

Sudantha


1 Answers

To sum up the as, use something like this:

type A = [(Int, Int, Int, Int)]

func :: A -> Int
func tuples = sum [a | (a, b, c, d) <- tuples]

Also note that a type alias must begin with an upper case letter. Lower case letters are used for type variables.

like image 128
hammar Avatar answered Dec 12 '25 01:12

hammar