deniok: (ухмыляюсь)
deniok ([personal profile] deniok) wrote2008-02-13 12:32 am
Entry tags:

Какой грязный хак :)

suminit :: [Int] -> Int -> Int -> (Int,[Int]) 
suminit xs len acc | len `seq` acc `seq` False = undefined -- :)))
                   | len == 0  = (acc,xs) 
                   | otherwise = case xs of []   -> (acc,[]) 
                                            x:xs -> suminit xs (len-1) (acc+x)
Найдено тут.

[identity profile] asviraspossible.livejournal.com 2008-02-12 09:52 pm (UTC)(link)
Это же честные bang-patterns. Возможно не самый плохой стиль для Haskell98 :)

[identity profile] deni-ok.livejournal.com 2008-02-12 10:19 pm (UTC)(link)
Угу, только выглядит как-то уродливо...

[identity profile] rvp74.livejournal.com 2008-02-13 10:30 am (UTC)(link)
suminit' :: [Int] -> Int -> Int -> (Int,[Int]) 
suminit' xs !len !acc | len == 0  = (acc,xs) 
                      | otherwise = case xs of []   -> (acc,[]) 
                                               x:xs -> suminit' xs (len-1) (acc+x)


Наверное, это тоже самое, но с сахаром. :)

[identity profile] deni-ok.livejournal.com 2008-02-13 02:54 pm (UTC)(link)
Да, это упомянутый выше bang-patterns. GHC-ное расширение.