[Haskell-cafe] Re: Roman Numerals and Haskell Syntax abuse

Christian Maeder maeder at tzi.de
Tue Jul 6 09:38:56 EDT 2004


Graham Klyne wrote:
>> now 134
>> roman=(!6);n!a|n<1=""|n>=t=s!!a:(n-t)!a|c>=t=s!!(2*e):c!a|1>0=n!(a-1)where(d,m)=a`divMod`2;e=d+m-1;s="ivxlcdm";c=10^e+n;t=10^d*(1+4*m) 
>>
> 
> Doesn't that need "import Array"?

No, "!" is user defined here (since ghc does not like "#" as infix)

btw, now 127:
roman=(!5);n!a|n<1=""|n>=t=s!!(a+1):(n-t)!a|c>=t=s!!(2*d):c!a|1>0=n!(a-1)where 
d=a`div`2;s="ivxlcdm";c=10^d+n;t=5^(d+1)*2^(a-d)

Christian



More information about the Haskell-Cafe mailing list