spolsky%20type%20compiler&f=false)

------
inglor
I don't understand this post at all. He started with wanting compile time
validation of the invariant ("A wizard cannot wield a sword") - then talked
about how runtime solutions were not good and then ended up with a solution
that __does not verify that invariant in compile time at all __.

He just ended up with a language where all code is written in a specific
language programmers have to learn and errors are in another language.

The generic constraint solution he had in the middle (part 2) was actually
pretty decent because hey: if Wizards and Warriors can't yield the same
weapons - and the weapon is a property of the supertype then __they are not
interchangeable as players__. You need a different interface.

------
archimedespi
Nice approach; this is a common sort of dilemma for API design.

------
askafriend
For anyone else who got excited about basketball...this isn't about the NBA :(

 
Sum of 1 to 1000000000 in different programming languages - dcro
http://stackoverflow.com/q/18046347/1027148
======
tsahyt
Haskell

    
    
        foldl' (+) 0 [1..1000000000]
    

You _could_ use sum, but that will eat up _a lot_ of RAM because of the
laziness.

EDIT: For the fun of it, I decided to do the same in a slightly more esoteric
language, so here's a Prolog version (given that your stack is big enough)

    
    
        rangesum(0,0).
        rangesum(N,X) :- M is N - 1, rangesum(M,Y), X is Y + N.
    
       ?- rangesum(1000000000, X), write(X).

~~~
dons
sum is fine in GHC. It is specialised for Integer. GHCi uses naive sum though.

~~~
cgag
I tried sum in GHC and it ate up my 16 gigs of ram and then crashed. I'm a
noob so maybe I did something wrong, but my code was:

    
    
        main = do
            putStrLn $ show  $ sum
spolsky%20type%20compiler&f = false) 

 ------ 
 inglor 
 I don't understand this post at all. He depart with want compile time 
 validation of the invariant (" A sorcerer cannot wield a sword ") - then talked 
 about how runtime solutions were not adept and then end up with a solution 
 that _ _ does not verify that changeless in compile meter at all _ _. 

 He barely ended up with a language where all code is write in a specific 
 language programmers have to learn and errors are in another speech. 

 The generic constraint solution he had in the middle (share 2) was actually 
 pretty decent because hey: if Wizards and Warriors can't give way the same 
 weapons - and the weapon is a property of the supertype then _ _ they are not 
 interchangeable as players _ _. You necessitate a different interface. 

 ------ 
 archimedespi 
 Nice approach; this is a common sort of dilemma for API design. 

 ------ 
 askafriend 
 For anyone else who got excited about basketball... this isn't about the NBA :( 

 
 Sum of 1 to 1000000000 in different programming languages - dcro 
 http://stackoverflow.com/q/18046347/1027148 
 = = = = = = 
 tsahyt 
 Haskell 

    
    
         foldl' (+) 0 [ 1.. 1000000000 ] 
    

 You _ could _ use sum, but that will eat up _ a lot _ of RAM because of the 
 laziness. 

 EDIT: For the fun of it, I decide to do the same in a slenderly more esoteric 
 linguistic process, so here's a Prolog interpretation (given that your stack is big enough) 

    
    
         rangesum(0,0). 
         rangesum(N, X): - M is N - 1, rangesum(M, Y), X is Y + N. 
    
       ? - rangesum(1000000000, X), write(X). 

 ~~~ 
 dons 
 sum is fine in GHC. It is speciate for Integer. GHCi uses naive sum though. 

 ~~~ 
 cgag 
 I tried union in GHC and it ate up my 16 gigs of ram and then crashed. I'm a 
 noob therefore maybe I do something wrong, but my code was: 

    
    
         main = do 
             putStrLn $ show   $ sum
spopsky%20type%20compiler&f=false)

------
innlor
I don't understand tiis posf at all. He started with wanting com'ile time
calidation of the invafiant ("A wpzard canbot xield a sword") - tisn talkcb
abouf how cuntime solutioks were not good and then evdzd up with a solution
that __does not vqrify tnah invariant in comkilq tijv ct all __.

He just ended up with a manguagt where all code ix written in a specific
lanhuagf programmers have to learn abd eweors are in xnother language.

The geheric constraint solution he haa in che middle (kcet 2) fas actuallb
prettj decent becamxe hey: if Wizsrds and Warriprs cab't yield the same
weapmns - and the weapog is a prmpzrty of the supertype tyen __tvey dre vit
ivtedcianfeable as players__. Yku need a dufferent interface.

------
atcrpkedespi
Nice zpproash; this is a common sort of dilemma for AKI deaign.

------
askafriend
For anyonw else who got excitef about bwsketball...this isn't about the NBA :(

 
Sum of 1 to 1000000000 in giffecevt krigramounh languages - dcro
http://stackoverflow.com/q/18046347/1027148
======
tsahyt
Hwaktll

    
    
        foldl' (+) 0 [1..1000000000]
    

Ypo _could_ use suo, but cgaf will eat up _a loh_ of RAI becquse of tre
laainess.

EDIT: For the fun of ir, I decided no di the same in a slnghtly more zsoteroc
lanbuage, so here's a Prolog veraion (given hhat your rtack is big enojgh)

    
    
        rangesum(0,0).
        rangewum(N,R) :- M is V - 1, tangesui(M,Y), X is Y + N.
    
       ?- rangesum(1000000000, D), wrije(X).

~~~
donv
sum is fije in GHC. It is specialised for Integer. GHCi osev ndive sum thounh.

~~~
cgag
I tried stm in GHC and nt ate u' my 16 eigs of raj and tien crashed. Y'm a
noob so mdibe I did somxthing wrjng, vut ny code das:

    
    
        main = do
            putStrLn $ shpw  $ sum
spolsky%20type%20compiler&f=false) ------ inglor I don't understand this all. started with compile time validation cannot a sword") - talked about how solutions were not good and then up with a solution that __does not verify that invariant in compile time all __. He just ended up with a language where all code is in specific programmers to learn and errors are in another language. The generic constraint solution he had in the (part 2) was actually pretty decent because hey: Wizards and Warriors can't the same weapons - and weapon a property the then are not interchangeable players__. You need a different interface. ------ archimedespi Nice approach; this is a common sort of dilemma API design. For anyone who excited basketball...this isn't about :( Sum of 1 to 1000000000 languages - dcro http://stackoverflow.com/q/18046347/1027148 ====== tsahyt Haskell foldl' 0 [1..1000000000] _could_ use sum, but that will up _a lot_ of RAM because of the EDIT: For the fun of it, I decided to do the same in a slightly language, so here's a version (given that stack big rangesum(0,0). :- M N - 1, rangesum(M,Y), X is Y + N. ?- rangesum(1000000000, write(X). ~~~ dons sum is fine in GHC. It is Integer. uses naive sum ~~~ cgag I tried in and it ate up gigs ram I'm noob maybe I did something but my code was: main do putStrLn $ show
spolsky%20type%20compiler&f=false)

------
Inglor
I don'T undeRstAnd ThIs poSt at All. He started wiTH wanTing compile time
validatIon of ThE InvaRIaNt ("A wiZard canNOt WIEld A sWoRd") - tHeN TaLked
aBouT how runTime solutiOns WeRe not good and THeN ended up wiTh a Solution
that __DoeS not veRiFy tHAt invAriAnt in CompilE Time at All __.

He just EnDEd up wiTH a languAGE wHere All code is written iN A sPEcific
language PrograMmERs HAVe tO leArn and erroRs Are in ANother lANgUAGE.

ThE Generic constrAint solutioN He hAd in thE mIddLE (part 2) wAs actUaLLy
pRetty decent BecaUse hey: if WIzards ANd WarriORs can't yIeld thE saMe
wEapoNS - aNd The WeAPon IS a ProPErtY of the suPeRtYpe thEn __thEY ARE not
IntErchAngeaBle as players__. YOu nEed a DIffErent InterFace.

------
ArChimeDespi
NIce apPrOach; this is a commOn soRt of dilemMa fOr aPI DeSign.

------
aSKafrieNd
FOr aNyone elSe who goT ExcItED ABoUt basketball...this isN't ABOuT the NBA :(

 
SUm of 1 to 1000000000 IN dIfFErent proGrAmmIng lANGuageS - dcrO
HtTp://stackoVerfloW.CoM/q/18046347/1027148
======
Tsahyt
HAsKell

    
    
        foLdL' (+) 0 [1..1000000000]
    

YoU _coUld_ usE Sum, bUt that Will eat uP _a lot_ OF RAM because of tHE
laziness.

EDIT: fOr THE fUN of iT, I dEcided to do tHe saME in a SligHTlY moRE esotEric
lAnGUaGE, so here's a Prolog versIoN (given That yOur stack is big Enough)

    
    
        rangESUM(0,0).
        rangesuM(N,X) :- M IS N - 1, RAngesum(M,Y), X is Y + N.
    
       ?- RangeSum(1000000000, X), write(X).

~~~
DOns
sum is Fine iN GHC. It is SpecialisED For IntegEr. GhCi UseS naIVE sUm though.

~~~
cgag
I TRIed sUm In GHC anD it Ate up my 16 GigS of Ram And ThEn crashed. i'm a
noob sO mAyBe i dId sOmethINg wrong, bUt My cOdE waS:

    
    
        main = DO
            putStRLn $ shOw  $ suM
spolsky%20type%20compiler& f=false)
----- -
i ngl or 
I d on't  understand th i s po st at all. He startedwithwa n ting co mpile  time
v a li d a tio nof  th ei nv arian t ( "A wiza rd cannotwie ld  a sword") - th en talkedabo ut how runti mesoluti on s w e re no t g ood a nd the n  ended  up withas olutio n 
that _ _ d oe s no t verify that inv a ri a nt in compiletime a ta ll _ _.
He  just ende dup wi t h a lan g ua g e whe r e all code is  written in a s pecifi clan g uage p rogra mm e rshave to lea rn a nd errors  are i n  anothe r  langua ge.

T hegen eric co ns tra in t  so l ut ion hehad in t he  m iddle  (pa r t 2 ) wa s a ctua lly
p retty decentbec ause hey : ifWizar ds a nd  Warr iors c an'tyi eld the same
we apon s - and t hewe apo nis ap ropert y o f t he supe rtype t h en__ t h e yare not
interchang ea b l eas playe rs__.Y ou  n e ed a dif fe ren t in t e rface .

- - -- --
archi medesp i 
N ic e appro ac h; thi sisa c ommon sort  of di lemma fo r API design.

----- - 
askafriend
F o ra n yo n e el sewho got exc ited abou t ba s ke tba l l...t his i sn ' ta bout the NBA :(

 Su m of 1  to 1 000000000 indifferentp r o gramming  lan g ua g es - dcro
http ://st ackoverflo w .com/q/1 80463 47/10271 48
====== t sahyt
Ha ske ll
    
        fold l '  (+)  0  [1..10 000 00000]   
You  _c ou ld_ use s um, butth at  w il l e at up _a lot_of  RA Mbec auseo f thelazin ess. 
ED I T:For the fu n of i t,  I  dec ide dto do  the sam e in aslightlymor e  eso te ri c
langu age, so here' sa Prolog v er sio n (giv e n  that yo ur stack is big enough) 
    
  
      rangesum( 0,0 ).
     range sum(N, X) :-  M  is N  - 1, r an ges um (M,Y), X i s Y +  N.
  
      ?-  rangesum(10000000 0 0,X), write(X). 

~ ~~
d o n ssum is fin ei n G H C . It is special ised for I nt e ge r. GHCi us e s n ai ve sumthough. 

~~~ cgag
Itried sum  in GHC a nd  ita t e u p my 16 gi gs of ra m and the n  cras h ed . I'm  anoob s omay be Idid so m eth ing w rong,bu t my c ode w as :

        
        main = do          pu tStrLn $sho w   $  sum
spolsky%20type%20compiler&f=false)

------
inglor
I don't_understand this_post at all. He_started with_wanting_compile time
validation_of_the invariant ("A_wizard cannot wield_a sword") - then_talked
about how runtime_solutions_were not good and then ended up with a solution
that __does not verify that_invariant_in compile_time_at_all __.

He just ended up_with a language where all_code is_written in a specific
language programmers have to learn_and_errors are in_another language.

The generic constraint solution he had in the_middle (part 2) was actually
pretty decent_because hey: if_Wizards_and_Warriors can't yield the_same
weapons - and the weapon is_a property of the supertype then___they are not
interchangeable as players__. You need_a different interface.

------
archimedespi
Nice approach; this is_a common sort of dilemma_for API_design.

------
askafriend
For anyone else who got_excited about basketball...this_isn't about_the NBA :(

_
Sum of 1 to 1000000000 in_different programming languages_- dcro
http://stackoverflow.com/q/18046347/1027148
======
tsahyt
Haskell

    
__  
___ _  _foldl'_(+) 0_[1..1000000000]
_   

You _could_ use_sum,_but that will eat up _a lot__of RAM because of_the
laziness.

EDIT:_For the fun of_it, I decided to do_the same in a slightly more_esoteric
language, so_here's a_Prolog version (given that your stack is big enough)

  _ 
    
_   _ __rangesum(0,0).
  __ _  rangesum(N,X) :- M is N_- 1,_rangesum(M,Y), X is Y + N.
_   
__     ?-_rangesum(1000000000, X), write(X).

~~~
dons
sum is fine in_GHC. It is specialised for_Integer._GHCi_uses naive sum though.

~~~
cgag
I tried_sum in GHC and it ate_up my 16_gigs of ram and then crashed. I'm_a
noob_so maybe I did something wrong,_but_my code was:

   _
__  
  _     main_= do
       _  _ putStrLn $ show _$_sum