- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
fibs = 0:1:zipWith (+) fibs (tail fibs)
fib = (fibs !!)
main = let
a = [fib 250000..]
b = a!!0
c = 1
in b `seq` print c
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
fibs = 0:1:zipWith (+) fibs (tail fibs)
fib = (fibs !!)
main = let
a = [fib 250000..]
b = a!!0
c = 1
in b `seq` print c
Haskell не может в not used expression elimination. Не используемые константы a и b не убрал из вычисления.
В результате видим пустую трату времени time: 13.15s :
http://ideone.com/41Q8D
И это то ленивом языке, не смотря на то, что эти вычисления не нужны. Можно писать в багтреккер.
P.S.: Когда уже хаскель в подсветку говнокода добавят?
0
data (,) a b = (,) a b
deriving Generic
data (,,) a b c = (,,) a b c
deriving Generic
data (,,,) a b c d = (,,,) a b c d
deriving Generic
.......
data (,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,) a b c d e f g h i j k l m n o p q r s t u v w x y z a_ b_ c_ d_ e_ f_ g_ h_ i_ j_ k_ l_ m_ n_ o_ p_ q_ r_ s_ t_ u_ v_ w_ x_ y_ z_ a__ b__ c__ d__ e__ f__ g__ h__ i__ j__
= (,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,) a b c d e f g h i j k l m n o p q r s t u v w x y z a_ b_ c_ d_ e_ f_ g_ h_ i_ j_ k_ l_ m_ n_ o_ p_ q_ r_ s_ t_ u_ v_ w_ x_ y_ z_ a__ b__ c__ d__ e__ f__ g__ h__ i__ j__
-- deriving Generic
{- Manuel says: Including one more declaration gives a segmentation fault.
Вот такая вот реализация туплов:
http://www.haskell.org/ghc/docs/7.4.1/html/libraries/ghc-prim-0.2.0.0/src/GHC-Tuple.html
0
-- | The unit datatype @()@ has one non-undefined member, the nullary
-- constructor @()@.
data () = () deriving Generic
data (,) a b = (,) a b
. . .
data (,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,) a b c d e f g h i j k l m n o p q r s t u v w x y z a_ b_ c_ d_ e_ f_ g_ h_ i_ j_ k_ l_ m_ n_ o_ p_ q_ r_ s_ t_ u_ v_ w_ x_ y_ z_ a__ b__ c__ d__ e__ f__ g__ h__ i__ j__
= (,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,) a b c d e f g h i j k l m n o p q r s t u v w x y z a_ b_ c_ d_ e_ f_ g_ h_ i_ j_ k_ l_ m_ n_ o_ p_ q_ r_ s_ t_ u_ v_ w_ x_ y_ z_ a__ b__ c__ d__ e__ f__ g__ h__ i__ j__
-- deriving Generic
{- Manuel says: Including one more declaration gives a segmentation fault.
. . .
*тяжелый вздох*
http://www.haskell.org/ghc/docs/latest/html/libraries/ghc-prim-0.2.0.0/src/GHC-Tuple.html#%28%29
0
chislo :: String -> Bool
chislo []=True
chislo (x:xs) =if (x=='1') then chislo xs
else if (x=='2') then chislo xs
else if (x=='3') then chislo xs
else if (x=='4') then chislo xs
else if (x=='5') then chislo xs
else if (x=='6') then chislo xs
else if (x=='7') then chislo xs
else if (x=='8') then chislo xs
else if (x=='9') then chislo xs
else if (x=='0') then chislo xs
else if (x=='.') then chislo xs
else False
haskell
0
fac 1 = 1
fac n = fac (n-1) * n
Вычисления факторила advanced-нубами с луркмора(с) на Haskell