RE: What's the '0' for in the version number?
Why is it GHC 5.02.2, 5.03 etc.? Wouldn't it be easier with 5.2.2, 5.3? I don't know, probably historical reasons: as far as I can remember, GHC's version numbers always had two digits after the decimal point. For historians, here is the announcement of the first release of GHC (0.06) archived thanks to Google: http://groups.google.com/groups?selm=16945.9203281558%40dcs.glasgow.ac.u koutput=gplain Cheers, Simon ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
RE: Weird porting problem with read
Well, I figured it out myself in the end... it's gcc dodginess :/ numberToInt checks the number that's been read against minBound :: Int. In the 64-bit STG C code this ends up being: _Cak7_=(-9223372036854775808)=(I_)(R1.p[1]); If I were to read the gcc warnings it would say: Text/Read/Lex.hc:40: warning: decimal constant is so large that it is unsigned and it seems to make a dodgy optimisation on that basis. If I change the constant to -(2^63-1) instead of -2^63 it works, and without the warning message. Which seems like a compiler bug to me, since -2^63 is a valid 64-bit signed number. I'll see what the gcc folks have to say. I've had similar problems before with minInt. I seem to recall that the C standard doesn't guarantee that this constant is representable in the int type: I think it has to do with the fact that the C standard doesn't proscribe 2's complement arithmetic, and in 1's complement you can't fit -2^63 in an int. Cheers, Simon ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: What's the '0' for in the version number?
G'day all. Why is it GHC 5.02.2, 5.03 etc.? Wouldn't it be easier with 5.2.2, 5.3? On Mon, May 06, 2002 at 11:44:03AM +0100, Simon Marlow wrote: I don't know, probably historical reasons: as far as I can remember, GHC's version numbers always had two digits after the decimal point. At least until you get into two-digit major version numbers, this way of doing things makes the filenames appear in version order when you type 'ls'. Cheers, Andrew Bromage ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
updating labelled fields
Hi, I often create structures like: data MyData = MyData { foo :: ..., bar :: ..., } and most of the time i do one of two things: 1) read values from the structure, as in: let x = (foo myData) in ... 2) update values in the structure, as in: let myData' = myData { foo = (foo myData)+1 } Only very rarely (usually only during intializization) do I actually put values into the structure that *don't* depend on their previous value. I end up with expresions like: ... myData { foo = (foo myData) + 1 ; bar = (bar myData) ++ bar ; ick = (ick myData) ! n ; ... } I was wondering if there existed any sort of update syntax. Obviously not real update, but enough to get rid of the (foo myData) parts of my epxression which really serve to just clutter up with expression. Perhaps something like: ... myData { foo - (+1) ; bar - (++bar) ; ick - (!n) ; ... } or the like, where x { ... y - e ... } is translated to x { ... y = e (y x) ... } (i only use - because that seems to be the default extension symbol, i guess because we don't want to trample symbols people might actually use.) Anyway, does such a thing exist, and, if not, is there any chance it could exist, or is it just syntactic salt to too many people? :) - Hal -- Hal Daume III Computer science is no more about computers| [EMAIL PROTECTED] than astronomy is about telescopes. -Dijkstra | www.isi.edu/~hdaume ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
Re: Syntax highlighting for KDE's Kate
On Sunday 05 May 2002 02:42 pm, Jorge Adriano wrote: To bad the literate haskell mode doesn't work with the LaTeX kind of literate programming - \begin{code} ... \end{code} - that's how I've been coding all my haskell programs lately :) Attached is my version of the haskell syntax highlighting file, hacked to work with both styles of literate comments. It uses the #stay and #pop features for changing contexts, so you probably need a recent version of Kate (I'm using kde 3.0) for it to work. I hope you find it useful. - Brian Huffman ?xml version=1.0 encoding=UTF-8? !DOCTYPE language SYSTEM language.dtd language name=Literate Haskell version=1.00 kateversion=2.0 section=Sources extensions=*.lhs mimetype=text/x-literate-haskell highlighting list name=reservedid item case /item item class /item item data /item item default /item item deriving /item item do /item item else /item item if /item item import /item item in /item item infix /item item infixl /item item infixr /item item instance /item item let /item item module /item item newtype /item item of /item item primitive /item item then /item item type /item item where /item /list contexts context attribute=10 lineEndContext=#stay name=Literate Comment RegExpr attribute=10 context=2 String=^/ StringDetect attribute=10 context=1 String=\begin{code}/ /context context attribute=10 lineEndContext=2 name=Code Block/ context attribute=0 lineEndContext=#pop name=Normal StringDetect attribute=10 context=#pop#pop String=\end{code}/ keyword attribute=1 context=#stay String=reservedid/ RegExpr attribute=2 context=#stay String=[A-Z][a-zA-Z0-9_']*/ RegExpr attribute=3 context=#stay String=[a-z_][a-zA-Z0-9_']*/ RegExpr attribute=3 context=#stay String=-*[!#$%amp;*+./:lt;=gt;?@\\^|~]-*/ Detect2Chars attribute=4 context=3 char=- char1=-/ Detect2Chars attribute=4 context=4 char={ char1=-/ DetectChar attribute=5 context=5 char=quot;/ RegExpr attribute=6 context=#stay String='[^'\\]'/ RegExpr attribute=6 context=#stay String='\\[abfnrtv\quot;\'\\]'/ RegExpr attribute=6 context=#stay String='\\\^[A-Z@\[\]\\^_]'/ RegExpr attribute=6 context=#stay String='\\([0-9]+|o[0-7]+|x[0-9a-fA-F]+)'/ RegExpr attribute=6 context=#stay String='\\(S(OH?|UB|YN|TX|I|P)|E(NQ|OT|SC|TB|TX|M)|DC[1234]|[BFGRU]S|[BD]EL|ACK|CAN|CR|DLE|FF|FL|HT|NAK|NUL|VT)'/ RegExpr attribute=7 context=#stay String=[0-9]+\.[0-9]+([eE][-+]?[0-9]+)?/ RegExpr attribute=8 context=#stay String=0([oO][0-7]+|[xX][0-9a-fA-F]+)/ RegExpr attribute=9 context=#stay String=[0-9]+/ /context context attribute=4 lineEndContext=#pop name=Comment 1/ context attribute=4 lineEndContext=#stay name=Comment 2 Detect2Chars attribute=4 context=4 char={ char1=-/ Detect2Chars attribute=4 context=#pop char=- char1=}/ /context context attribute=5 lineEndContext=#pop name=String LineContinue attribute=6 context=#stay/ RegExpr attribute=6 context=#stay String=\\[abfnrtv\quot;\'\\amp;]/ RegExpr attribute=6 context=#stay String=\\\^[A-Z@\[\]\\^_]/ RegExpr attribute=6 context=#stay String=\\([0-9]+|o[0-7]+|x[0-9a-fA-F]+)/ RegExpr attribute=6 context=#stay String=\\(S(OH?|UB|YN|TX|I|P)|E(NQ|OT|SC|TB|TX|M)|DC[1234]|[BFGRU]S|[BD]EL|ACK|CAN|CR|DLE|FF|FL|HT|NAK|NUL|VT)/ DetectChar attribute=5 context=#pop char=quot;/ /context /contexts itemDatas itemData name=Normal Text defStyleNum=dsNormal/ itemData name=Keyword defStyleNum=dsKeyword/ itemData name=TyCon defStyleNum=dsDataType/ itemData name=Identifier defStyleNum=dsNormal/ itemData name=Comment defStyleNum=dsComment/ itemData name=String defStyleNum=dsString/ itemData name=ChardefStyleNum=dsChar/ itemData name=Float defStyleNum=dsFloat/ itemData name=HexOctaldefStyleNum=dsBaseN/ itemData name=Integer defStyleNum=dsDecVal/ itemData name=Lit Comment defStyleNum=dsOthers/ /itemDatas /highlighting general comments comment name=singleLine start=--/ comment name=multiLine start={- end=-}/ /comments keywords casesensitive=1/ /general /language
Re: Bug in the scaling of randoms ...
Dimitre Novatchev wrote on May 4, 2002: In his excellent book Simon Thompson defines scaling of the elements of a sequence of random numbers from the interval [0, 65535] to an interval [s,t] in the following way (top of page 368): scaleSequence :: Int - Int - [Int] - [Int] scaleSequence s t = map scale where scale n = n `div` denom + s range = t - s + 1 denom = modulus `div` range where modulus = 65536 However, the following expression: e4000 = (scaleSequence 1 966 ([65231] ++ [1..965]))!!0 evaluates to 974 -- clearly outside of the specified interval. Here's the algorithm for mapping of ranges of integers that is provably correct. We aim to find a function sc(n) defined over integers 0 = n = M so that sc(0) - s (given integral number) sc(M) - t (given integral number), t=s and 0=a b == sc(a) = sc(b) Such a function sc(n) is given by the following expression: sc(n) = (n*(t-s)) `div` M + s Proof: sc(0) = s sc(M) = (M*(t-s)) `div` M + s = t ab == a*(t-s) b*(t-s) == (a*(t-s)) `div` M = (b*(t-s)) `div` M The assertion that 0=ab == a `div` M = b `div` M for M 0 can easily be proven by contradiction. Indeed, given the facts (a `div` M)* M = a - ra, 0= ra = M-1 (b `div` M)* M = b - rb, 0= rb = M-1 and an assumption a `div` M b `div` M we see a = M*(a `div` M) + ra = M*(b `div` M + x) + ra { where x = 1 } = b - rb + ra + M*x = min{ b - rb + ra + M*x over ra in [0,M-1], rb in [0,M-1]} = b - (M-1) + M*x = b + 1 + M*(x-1) { x = 1 } b {contradiction} Thus the correct algorithm reads scaleSequence :: Int - Int - [Int] - [Int] scaleSequence s t = map scale where scale n = (n*range) `div` maxn + s range = t - s maxn= modulus - 1 modulus = 65536 Given your example, Main any (==966) (scaleSequence 1 966 ([65231] ++ [1..965] ++[65565])) True Main any (966) (scaleSequence 1 966 ([65231] ++ [1..965] ++[65565])) False ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
Re: updating labelled fields
I often create structures like: data MyData = MyData { foo :: ..., bar :: ..., } That makes 2 of us :-) and most of the time i do one of two things: 1) read values from the structure, as in: let x = (foo myData) in ... 2) update values in the structure, as in: let myData' = myData { foo = (foo myData)+1 } 1) I've used datatypes with labeled fields mostly to pass around implicit values. If that is your case then there is a way around it. Declare the datatype as data MyData = MyData { foo_ :: fooType, bar_ :: ..., } and then declare foo :: (?implicitdata :: MyData)= fooType foo = foo_ ?yourdata So when you work in a contex that depends on some implicit data you can just use foo. I've used this *a lot* lately. 2) Yes. My method now is declaring set and apply functions to every field of my data structure. fooAp f ni=ni{foo=f(foo ni)} fooSet x = fooAp (const x) Only very rarely (usually only during intializization) do I actually put values into the structure that *don't* depend on their previous value. I end up with expresions like: ... myData { foo = (foo myData) + 1 ; bar = (bar myData) ++ bar ; ick = (ick myData) ! n ; ... } Yeap quite ugly isn't it? :-) I was wondering if there existed any sort of update syntax. Obviously Nope, not that I know of. not real update, but enough to get rid of the (foo myData) parts of my epxression which really serve to just clutter up with expression. Perhaps something like: ... myData { foo - (+1) ; bar - (++bar) ; ick - (!n) ; ... } Yes looks nice, thought about something like that before too. or the like, where x { ... y - e ... } is translated to x { ... y = e (y x) ... } (i only use - because that seems to be the default extension symbol, i guess because we don't want to trample symbols people might actually use.) Anyway I'd prefer to have some way to 'derive' apply and set functions. Something like data MyData = MyData { foo :: fooType, bar :: ..., } deriving (Set, Apply) Using the keyword deriving would probably be a bad idea though :) The set and apply functions could be derived with a standard postfix or maybe prefix... fooAp or apFoo. Maybe we could introduce sintax to specify it... deriving (Set with set, Apply with ap) I don't know... I'm just brainstorming right now. Having actual functions is important. I don't think I have to explain why to people in this mailing list :-) Anyway, does such a thing exist, and, if not, is there any chance it could exist, or is it just syntactic salt to too many people? :) I whish you better luck than I've had so far whenever making posts about this same issue ;) J.A. ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
Re: Bug in the scaling of randoms ...
Thank you! --- [EMAIL PROTECTED] wrote: [nice proof snipped] Thus the correct algorithm reads scaleSequence :: Int - Int - [Int] - [Int] scaleSequence s t = map scale where scale n = (n*range) `div` maxn + s range = t - s maxn= modulus - 1 modulus = 65536 Given your example, Main any (==966) (scaleSequence 1 966 ([65231] ++ [1..965] ++[65565])) True Main any (966) (scaleSequence 1 966 ([65231] ++ [1..965] ++[65565])) False In your examples you added one more element to the end of the list. Its value is greater than maxn -- maybe I'm missing something? Cheers, Dimitre Novatchev. __ Do You Yahoo!? Yahoo! Health - your guide to health and wellness http://health.yahoo.com ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
Re: updating labelled fields
I just fudgeted around in the ghc source code and this doesn't seem to be a change that would require a lot of work. Briefly, the changes that would need to be made would be: 1) In the parser, change bind so that in addition to qname '=' exp you can also have qname 'somefunkysymbol' exp And change the return type from (a,b,Bool) to (a,b, Either () Bool) and then for the normal case, returh Right False and for the update case return Left (). 2) in the mkRecConstrOrUpdate function, when you have a conid applied to an update, make sure there are no Left () guys in the list; otoh, if the guy sitting in from of the { is an exp, do a map (mkRecUpdate exp) on the list where this function is something like: mkRecUpdate exp (a,b,Right c) = (a,b,c) mkRecUpdate exp (a,b,Left ()) = (a,HsApp b (HsApp (HsVar a) exp),False) -- warning, this isn't 100% correct, but it's the basic idea 3) recompile ghc I wouldn't at all mind making this addition if I had a sense that it would actually be accepted and that people weren't going to go crazy over the syntax. Would something like - be preferred or something like $=? - Hal -- Hal Daume III Computer science is no more about computers| [EMAIL PROTECTED] than astronomy is about telescopes. -Dijkstra | www.isi.edu/~hdaume On Tue, 7 May 2002, Bryn Humberstone wrote: Hi Hal, 2) update values in the structure, as in: let myData' = myData { foo = (foo myData)+1 } I do this a lot too, and think it would be lovely to have some sugar for it. My original idea for the syntax was something like myData = myData { foo $= (+1), bar $= (*2) } just because $ is a bit reminiscent of function application. But I'm not really fussed; as long as some syntax for it appeared in the language. -- Bryn -- Bryn Humberstone + Email [EMAIL PROTECTED] + Web http://bryn.alphalink.com.au/ ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
Re: updating labelled fields
On Mon, May 06, 2002, Hal Daume III wrote: I wouldn't at all mind making this addition if I had a sense that it would actually be accepted and that people weren't going to go crazy over the syntax. Would something like - be preferred or something like $=? - Hal Why not $= ? ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
Re: updating labelled fields
On Monday 06 May 2002 23:28, Hal Daume III wrote: I wouldn't at all mind making this addition if I had a sense that it would actually be accepted and that people weren't going to go crazy over the syntax. Would something like - be preferred or something like $=? I'd still prefer having some way to automaticly derive 'apply' functions. There is already nice syntax for setting a field value and I always end up defining 'set' functions to each and every field because I want to pass them as arguments. Imagine you have an STRef to a labeled datatype, lets call it stdata. You want to apply some function g to field foo of that structure. modifySTRef (fooAp g) stdata Changing its value to x modifySTRef (fooSet x) stdata With syntatic sugar only you'd have to read the reference, apply the function to the field and then update it. IMO, 'set field' and 'apply to field' functions are as usefull as the 'field projection' functions that are derived from the definition of the labeled datatype. Anyway I agree that it would be nice to have special syntax for updates. I'll use it if I have it available. On Monday 06 May 2002 23:42, David Feuer wrote: Why not $= ? Yeap very nice in deed. I'd vote for this one. J.A. ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
Proper scaling of randoms
This message derives an integer interval mapping function that is not only provably within the given range but also uniform. This is the function to use when mapping random integers from one interval to a smaller one. Problem: given an integer n within [0..maxn], design a scaling function sc(n) that returns an integer within [s..t], t=s. The function sc(n) must be 'monotonic': 0=a b == sc(a) = sc(b) and it must map the ends of the interval: sc(0) - s and sc(maxn) - t. One such function has been designed by Simon Thompson in his book: sct(n) = n `div` ((maxn+1) `div` (t-s+1)) + s Another function has been derived in the previous message on this list: sc1(n) = (n*(t-s)) `div` maxn + s The sct() function has a serious drawback: it is not guaranteed that sct(n) = t (more about it below). The sc1() function is provably within the given range, and monotonic. Alas, it is not uniform. When it comes to mapping of random integers, the mapping function must possess an extra property: it must map uniformly. That is, given random numbers within [0..maxn] such that Prob(n==i) - const, we must aim at Prob(sc(n)==i') - const forall i' in [s..t]. The mapping function sc1(n) does not have this property. Any mapping function sc(n) from [0..maxn] to [s..t] for (t-s+1) (maxn+1) maps several integers from the source interval to one integer of the target interval. An integer of the target interval therefore denotes an equivalence class of the integers from the source interval. The uniformity property will be satisfied only if the equivalence classes have the same size. This is only possible if (maxn+1) `rem` (t-s+1) == 0. Given this condition, the original Thompson's algorithm works. If (t-s+1) divides (maxn+1) exactly (i.e., exists denom integer. denom*(t-s+1) == maxn+1), we have j*denom = n = j*denom+denom-1 == sct(n) = j+s, all j=0..(t-s) Thus each equivalence class has the size denom, and mapping is perfectly uniform. As a consequence, s = sct(n) = t, given our assumption (maxn+1) `rem` (t-s+1) == 0. If this assumption does not hold, sct(n) may be greater than t (which Dimitre Novatchev has demonstrated). Alas, in this case there is no perfectly uniform mapping. The Thompson's algorithm misbehaves. The worst case for the algorithm is when t = s + (maxn+1)/2. For example, this occurs when we try to map [0..65535] to [0..32768]. In this case, t-s+1 = 32769, and denom = 65536 `div` 32769 == 1, thus the mapping becomes sct(n) = n. In almost half of the time, this mapping exceeds the upper limit 32768. OTH, the mapping sc1(n) = n*(maxn+1)/2 `div` maxn + s behaves in this pathological case rather well. Not only sc1(n) = t (this is always guaranteed) but also the mapping is uniform: all equivalence classes of the source interval [0..65535] except the last two classes have the size of two. Thus the best solution should be to average sc1(n) and sct(n). This averaging is done by the formula sca = (n*(t-s) + (n*(denom-1) `div` denom)) `div` maxn + s where denom = (maxn+1) `div` (t-s+1) It is easy to see that sca(0) - s. sca(maxn) = (maxn*(t-s) + (maxn*(denom-1) `div` denom)) `div` maxn + s = (maxn*(t-s) + p) `div` maxn + s {where 0= p = (maxn*(denom-1) `div` denom) = maxn-1 } = t-s+s = t It is easy to show that sca(n) is monotonic (as defined above). If maxn+1 is evenly divisible by (t-s+1) (that is, denom*(t-s+1) == maxn+1), we have j*denom = n = j*denom+denom-1 == sca(n) = j+s, all j=0..(t-s) This requires a proof. We have: sca(j*denom) = (j*denom*(t-s) + (j*denom*(denom-1) `div` denom)) `div` maxn + s = (j*denom*(t-s) + j*(denom-1)) `div` maxn + s = j*(denom*(t-s) + denom-1) `div` maxn + s = j*maxn `div` maxn + s = j+s sca(j*denom+denom-1) = ((j*denom+denom-1)*(t-s) + ((j*denom+denom-1)*(denom-1) `div` denom)) `div` maxn + s = ((j*denom+denom-1)*(t-s) + (j+1)*(denom-1)-1) `div` maxn + s = (j*maxn + (denom-1)*(t-s+1)) `div` maxn + s = j+s The required result then follows by the monotonicity property. In the most pathological case of maxn= 65535, s=0, t= 32768. We have denom = 1 and sca(n) becomes sc1(n), which, in this case, behaves very well. Thus the sca mapping is the optimal one. It is guaranteed to keep the result within the specified bounds at all times. When the perfect uniformity of mapping is possible, it is always achieved. The implementation isn't too complex either. scaleSequence :: Int - Int - [Int] - [Int] scaleSequence s t = map scale where scale n = (n*range + ((n*(denom-1)) `div` denom)) `div` maxn + s range = t - s maxn= modulus - 1 modulus = 65536 denom = (maxn+1) `div` (t-s+1) Main any(966) (scaleSequence 1 966 [0..65535]) False Main any(==966) (scaleSequence 1 966 [0..65535]) True Main any(32768) (scaleSequence 0 32768 [0..65535]) False test = let sq =
Re: updating labelled fields
DrIFT which i am now maintaining can derive such utility functions out of the box. just add a {-!deriving: update -} to get update functions for every labeled field in a datatype. quite useful, I have not updated the web page yet, but the new DrIFT homepage will be at http://homer.netmar.com/~john/computer/haskell/DrIFT/ On Mon, May 06, 2002 at 07:36:30PM +0100, Jorge Adriano wrote: Anyway I'd prefer to have some way to 'derive' apply and set functions. Something like data MyData = MyData { foo :: fooType, bar :: ..., } deriving (Set, Apply) Using the keyword deriving would probably be a bad idea though :) The set and apply functions could be derived with a standard postfix or maybe prefix... fooAp or apFoo. Maybe we could introduce sintax to specify it... deriving (Set with set, Apply with ap) I don't know... I'm just brainstorming right now. Having actual functions is important. I don't think I have to explain why to people in this mailing list :-) Anyway, does such a thing exist, and, if not, is there any chance it could exist, or is it just syntactic salt to too many people? :) I whish you better luck than I've had so far whenever making posts about this same issue ;) -- --- John Meacham - California Institute of Technology, Alum. - [EMAIL PROTECTED] --- ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell