deniok: (ухмыляюсь)
[personal profile] deniok
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)
Найдено тут.

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

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

Date: 2008-02-13 10:30 am (UTC)
From: [identity profile] rvp74.livejournal.com
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)


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

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

Profile

deniok: (Default)
deniok

February 2022

S M T W T F S
  12345
6789101112
13141516171819
20212223 242526
2728     

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 16th, 2025 04:49 pm
Powered by Dreamwidth Studios