deniok: (typed lambda)
deniok ([personal profile] deniok) wrote2008-11-05 12:40 am
Entry tags:

GHC 6.10.1: первая проба

Среди новинок стоит отметить синтаксический сахар Generalised (SQL-Like) List Comprehensions. Не могу не привести пример последнего из документации (это моя сессия GHCi):
Prelude> :s -XTransformListComp 
Prelude> :m GHC.Exts 
Prelude GHC.Exts> let employees = [ ("Simon", "MS", 80) , ("Erik", "MS", 100) , 
("Phil", "Ed", 40) , ("Gordon", "Ed", 45) , ("Paul", "Yale", 60)]
Prelude GHC.Exts> let output = [ (the dept, sum salary) | (name, dept, salary) 
< - employees , then group by dept , then sortWith by (sum salary) , then take 5 ] 
Prelude GHC.Exts> output 
[("Yale",60),("Ed",85),("MS",180)]
Мы можем увидеть, что Эрик получает в MS больше Саймона, и это, соратники, самое удивительное! Отмечу также, что в Эдинбургском университете зарплаты ниже, чем в Йельском.

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting