Re: [Haskell-cafe] Debugging partial functions by the rules
Hi To see at a glance the various bug reports about fromJust you can search the bug database: http://bugs.darcs.net/[EMAIL PROTECTED]&@sort=activity&@group=priority&@search_text=fromJust I count 7 bugs. I would be interested to see the results of static analysis tools (Catch?) or applying Oleg's strategy. Any volunteers? Unfortunately darcs is too big, and too unhaskell-98 to go through Catch as it currently stands. In reality the best strategy would probably be to use Catch on darcs, then where Catch is unable to automatically verify the program use Oleg's techniques and other rewritings until Catch can verify everything. Just taking a random example (the first fromJust I stumbled upon): http://abridgegame.org/repos/darcs-unstable/Population.lhs, cleanPop The requirement here is that the modifiedHowI field of the 2nd field of the Pop at the top must be not a removal. Figuring out in an existing code-base whether that is a general invariant for Pop, true in this specific case, or any other random combination is quite a hard problem! Thanks Neil ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Wiki page for rewrite rules tips, types and tricks
After suggesting solutions based on rewrite rules to three different questions this week, I though maybe we better have a wiki page on using rewrite rules for non-traditional ad-hoc tricks. http://haskell.org/haskellwiki/Playing_by_the_rules If you've used rewrite rules for something fun (other than implementing a major deforestation system), please add it to the page. -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Debugging partial functions by the rules
This good long thread prompted Don and I to take a look at the darcs source (this is current darcs-unstable). You can get the darcs source at: darcs get http://abridgegame.org/repos/darcs-unstable Here are some data points (without interpretation): In impossible.h we have the definitions: import Bug ( bug ) #define impossible (bug $ "Impossible case at "++__FILE__++":"++show (__LINE__ :: Int)++" compiled "++__TIME__++" "++__DATE__) #define fromJust (\m_fromJust_funny_name -> case m_fromJust_funny_name of {Nothing -> bug ("fromJust error at "++__FILE__++":"++show (__LINE__ :: Int)++" compiled "++__TIME__++" "++__DATE__); Just x -> x}) The second definition gives bug reports like the following: fromJust error at Push.lhs:136 compiled 11:51:58 Jun 16 2006 Please report this to [EMAIL PROTECTED], If possible include the output of 'darcs --exact-version'. To see at a glance the various bug reports about fromJust you can search the bug database: http://bugs.darcs.net/[EMAIL PROTECTED]&@sort=activity&@group=priority&@search_text=fromJust I count 7 bugs. Some other datapoints: $ grep fromJust *.lhs *.hs | wc -l 101 $ grep fromMaybe *.lhs *.hs | wc -l 7 $ grep maybe *.lhs *.hs | wc -l 120 I would be interested to see the results of static analysis tools (Catch?) or applying Oleg's strategy. Any volunteers? thanks! Jason ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Are associated types synonyms like type classes?
Brian Smith: > When using AT then we have to decide what part of the abstraction is > the class and what part is the associated type. Sometimes this seams > arbitrary. If we have: > > class A a where > type B b > f :: a -> B b > instance A Int where > type B = Bool > f = (==0) > > Can't we also rewrite it as: > > class B b where > type A a > f :: A a -> b > instance B Bool where > type A = Int > f = (==0) If it is arbitrary, you should use a two parameter class. The bias in an associated type is on purpose; ie, an associated type should be used if one type depends on the other. Bulat wrote: > > Also, has anybody written a paper on the differences between > > typeclasses + associated types and ML's module system + > overloading? > > "ML Modules and Haskell Type Classes: A Constructive Comparison" > http://www.informatik.uni-freiburg.de/~wehr/diplom/Wehr_ML_modules_and_Haskell_type_classes.pdf In addition to this comparison, there is now also a proposal for type classes with associated types as a mode of use of ML modules. See our forthcoming POPL paper: http://www.cse.unsw.edu.au/~chak/papers/DHC07.html Ie, this gives you ML modules + overloading. Manuel ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re[2]: [Haskell] I18N, external strings
bulat.ziganshin: > Hello Axel, > > Friday, November 17, 2006, 11:27:00 AM, you wrote: > > > (l_ "Translate this") > > > is compiled into a C string constant, that GHC then turns lazily into a > > list of characters, which l_ then turns into an array in C land to pass > > to the gettext function, which, in turn, returns a new C string array > > that has to be turned into a Haskell string again. So I'm glad Lennart > > proposed to turn String into a class which would then make it possible > > to pass a pointer to a contant C string to gettext. > > i'm not sure that you are right. GHC can perform compile-time computation > of constant expressions. Don Bruce should know better, once he pointed > out how a String constant can be turned into ByteString one at compile > time Quite so, using (what else?) rewrite rules! Supposing I want to use a ByteString literal (and lennart hasn't yet committed overloaded strings into GHC..) I can write: import qualified Data.ByteString.Char8 as C main = C.putStrLn mystring mystring = C.pack "rewrite rules are fun!" and it is compiled by GHC to: mystring_rDR = Data.ByteString.Char8.pack (GHC.Base.unpackCString# "rewrite rules are fun!"#) Main.main :: GHC.IOBase.IO () Main.main = Data.ByteString.putStrLn mystring_rDR :Main.main :: GHC.IOBase.IO () :Main.main = GHC.TopHandler.runMainIO @ () Main.main Now, the string literals has been packed by GHC for us into a Addr#, pointing to a proper C string. Now, we'd like to remove that intermediate unpackCString#, and just pack the string literal straight into a ByteString, avoiding an intermediate list. So we add a rewrite rule: {-# RULES "pack/packAddress" forall s . pack (unpackCString# s) = B.packAddress s #-} Now, when compiled with -O -fglasgow-exts, we get: 1 RuleFired 1 FPS pack/packAddress and the code is transformed as follows: mystring = Data.ByteString.Base.packAddress "rewrite rules are fun!" to mystring = Data.ByteString.Char8.pack (GHC.Base.unpackCString# "rewrite rules are fun!"#) and then the rewrite rule kicks in, and we construct a new ByteString directly from the Addr#, via a call to strlen to get the length: mystring = let addr#_a146 :: GHC.Prim.Addr# addr#_a146 = "rewrite rules are fun!"# in case Data.ByteString.Base.$wccall addr#_a146 s2#_a1Q8 of (# ds3_a1Re, ds4_a1Rf #) -> Data.ByteString.Base.PS addr#_a146 (GHC.ForeignPtr.PlainForeignPtr var#_a1Q9) 0 (GHC.Prim.word2Int# ds4_a1Rf) *exactly* what we'd like. So at runtime, this string will require only a call to strlen to build. If the compiler was able to pack string literals to CStringLen, tagging them with their length, we could avoid the O(n) strlen call, and directy build ByteStrings in O(1), using unsafePackAddress#, which takes a length field. I.e. something like: mystring = let addr#_a146 :: GHC.Prim.Addr# addr#_a146 = "rewrite rules are fun!"# len:: GHC.Prim.Int# len= 22 in Data.ByteString.Base.PS addr#_a146 (GHC.ForeignPtr.PlainForeignPtr var#_a1Q9) 0 len# -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Debugging partial functions by the rules
On Saturday 18 November 2006 00:37, Neil Mitchell wrote: > Hi > > > > How controversial would a proposal to {-# DEPRECATE fromJust #-} be, in > > > favour of: > > > > > > Just _ = x -- which will give you the precise line number > > > > > > It seems to me this is one cause of mysterious newbie errors we > > > could easily discourage, with little harm. > > > > Btw, I'm not seriously suggesting removing it ;) > > It could be discouraged ever so slightly in the haddocks though. > > I strongly disagree. If we are removing things that confuse newbies > why not start with higher rank types, MPTC's and GADT's ;) > > fromJust is simple, useful and clear. What you mean is that > implementations aren't very good at debugging this. It seems unfair to > blame partial functions for the lack of a debugger. If a call stack > was automatically output every time a fromJust failed would this even > be something people complained about? Well, I strongly disagree. :) I suspect I would be classified as a newbie relative to most posters on this list but here's my thoughts anyway... I chose to learn haskell largely because I thought the static type safety would help eliminate bugs, I've never once been happy when I've needed to fire up a debugger or add trace statements and I hoped they would become things of the past. One of my initial responses to haskell was disappointment upon seeing head, fromJust and the like. 'Those look nasty', I sez to meself. From day one I've tried to avoid using them. Very occasionally I do use them in the heat of the moment, but it makes me feel unclean and I end up having to take my keyboard into the bathroom for a good scrubbing with the sandsoap. The disappointment has pretty much changed to frustration since reading Oleg, and others, type-hackery work. I realise the problems are just poor/limited usage of haskell, not inherent in the language. Unfortunately I can understand the 'right' solutions but still have trouble formulating them myself. I'm hoping that if I hang out in the type-hackery 'hot zone' long enough I'll start emitting enough picoOlegs myself to solve simple problems. ;) My view is that if I can reason about my program and know a static property I want to be able to stamp this into the types and have my reasoning validated during compilation. But existing library code with weak typesafety is a large inertial mass, when trying to do something 'right' the interfacing is a daunting prospect. In general I'd rather have effort go into promoting 'right' solutions, and making those solutions easier to express, than going into debuggers for 'wrong' solutions. Daniel ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Debugging partial functions by the rules
On Fri, Nov 17, 2006 at 11:37:12AM +, Neil Mitchell wrote: > fromJust is simple, useful and clear. What you mean is that > implementations aren't very good at debugging this. It seems unfair to > blame partial functions for the lack of a debugger. If a call stack > was automatically output every time a fromJust failed would this even > be something people complained about? indeed. jhc debugs this quite fine. when you use it the wrong way you get Main.hs:23:33:fromJust Nothing as your error message. or you should at least. likewise for head, tail, undefined, etc.. actually any function including ones you write yourself for which you give the SRCLOC_ANNOTATE pragma. boy I want to have the time to port that to ghc... a six pack of beer for whoever does :) John -- John Meacham - ⑆repetae.net⑆john⑈ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Try Graphics.SOE.Gtk ? was Re: Updated School of Expression Sources?
"Justin Bailey" <[EMAIL PROTECTED]> writes: > I downloaded the SOE sources from http://www.haskell.org/soe and found they > were not compatible with the my version of WinHugs (Sep 2006). I have two > questions: > > 1) Is an updated version of those sources available? > 2) If not, would someone like to host mine? I updated all the source files > so they at least load without error. Mostly it involved changing a few > import statements. I also had to make some updates to the included Haskore > files. Another option is Duncan Coutts' reimplementation of Graphics.SOE in GTK2: http://haskell.org/~duncan/soegtk/ -- I've tried to teach people autodidactism,| ScannedInAvian.com but it seems they always have to learn it for themselves.| Shae Matijs Erisson pgpSzJF44HCPT.pgp Description: PGP signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Collection of objects?
On Fri, 17 Nov 2006 20:04:22 +0100, Steve Schafer <[EMAIL PROTECTED]> wrote: myList = [(Integer 42), (Character 'a'), (Float 3.14159)] You can leave out the parentheses, making even simpler: myList = [Integer 42, Character 'a', Float 3.14159] -- Met vriendelijke groet, Henk-Jan van Tuyl -- http://Van.Tuyl.eu/ -- Using Opera's revolutionary e-mail client: https://secure.bmtmicro.com/opera/buy-opera.html?AID=789433 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Newbie; Can't Install Hat From Source
Thanks to Malcolm Wallace I got Hat installed and working from darcs using: 'darcs get http://darcs.haskell.org/hat' cd'ing in to the 'hat' directory and doing an 'sh start'. This last step makes all scripts executable. Appreciate the support... Deech From: Malcolm Wallace <[EMAIL PROTECTED]> To: haskell-cafe@haskell.org CC: [EMAIL PROTECTED] Subject: Re: [Haskell-cafe] Newbie; Can't Install Hat From Source Date: Thu, 16 Nov 2006 10:42:10 + "Aditya Siram" <[EMAIL PROTECTED]> wrote: > I have been trying to install Hat for the last couple of days but GHC > does not recognize it as a package. I compiled 2.05 from source, but > at the 'make install' step I see this error message: > > Installing hat package for ghc under > /usr/local/lib/hat-2.05/ix86-Linux/ghc-606 > ghc-pkg: cannot find package hat <-ERROR MESSAGE! This error message can be safely ignored - it comes from a requirement to support several different versions of ghc, each of which has a different interface to the package manager ghc-pkg. > ghc-pkg: package hat-2.4 is already installed > > /usr/local/lib/ghc-6.6/package.conf: > ... > /home/deech/.ghc/i386-linux-6.6/package.conf: > (hat-2.4)> For some reason it thinks that hat-2.4 is installed. This is one of a couple of bugs in the 2.05 package. The .cabal file simply had the wrong version number in it. > Bad interface file: > /usr/local/imports/hat-2.05/ghc-606/Hat/PreludeBasic.hi > Something is amiss; requested module hat-2.4:Hat.PreludeBasic > differs from name found in the interface file hat:Hat.PreludeBasic And this is the other bug: the Hat library package was built using "-package-name hat" instead of "-package-name hat-2.05" (as now required by ghc-6.6 and above). I have re-rolled the Hat-2.05 distribution package with these two very minor bugfixes. Please try downloading it again, and re-building. Regards, Malcolm ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe _ View Athletes Collections with Live Search http://sportmaps.live.com/index.html?source=hmemailtaglinenov06&FORM=MGAC01 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] Updated School of Expression Sources?
My understanding is that the SOE sources only work with an old version of Hugs. It is available at : http://www.haskell.org/soe/software.htm Regards, Deech From: "Justin Bailey" <[EMAIL PROTECTED]> To: haskell-cafe@haskell.org Subject: [Haskell-cafe] Updated School of Expression Sources? Date: Fri, 17 Nov 2006 09:03:11 -0800 I downloaded the SOE sources from http://www.haskell.org/soe and found they were not compatible with the my version of WinHugs (Sep 2006). I have two questions: 1) Is an updated version of those sources available? 2) If not, would someone like to host mine? I updated all the source files so they at least load without error. Mostly it involved changing a few import statements. I also had to make some updates to the included Haskore files. Also, I found the some of the programs included crash Hugs without warning. For example, evaluating "test cball5" in the file "Fal.lhs" will crash Hugs after running for a few seconds, or if the mouse is moved over the window. Does anyone know why that may occur? Justin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe _ Share your latest news with your friends with the Windows Live Spaces friends module. http://clk.atdmt.com/MSN/go/msnnkwsp007001msn/direct/01/?href=http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mk ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Collection of objects?
On Fri, 17 Nov 2006 18:36:30 +0100, you wrote: >But I need something which is heterogeneous and non-fixed length. I'm >used do Java, and this switch to functional languages is very strange to >me. So, to be clear, I need something like LinkedList in java. In an attempt to leverage your existing Java knowledge... In Java, while the "things" in your list are heterogeneous at some level, they are homogeneous at another: They are all instances of Object (or a subclass thereof). You can't, for example, put an int in your list. And in fact, that's a primary reason for the existence of the Integer class--it makes your int look like an Object, so that you can treat it like one. (And similarly for Character, Float, Double, etc.) So you do the analogous thing in Haskell: First, you ask yourself, "What kinds of things do I want to put in my list?" Once you have the answer to that, you ask, "Are these things homogeneous at some level?" If they are, then you make your list a list of those homogenous things (actually, the compiler generally does it for you). If they aren't, then you wrap them up in a homogeneous wrapper in exactly the same way as you wrap your int in an Integer, your double in a Double, etc., in Java. Some of the other replies have shown you how to declare this; it's trivially simple: data MyHomogeneousWrapper = Integer Int | Character Char | Float Float deriving Show Finally, constructing new instances of this homogenous wrapper in Haskesll is just like it is in Java: myList = [(Integer 42), (Character 'a'), (Float 3.14159)] vs. myList = new LinkedList(); myList.add(new Integer(42)); myList.add(new Character('a')); myList.add(new Float(3.14159)); Steve Schafer Fenestra Technologies Corp. http://www.fenestra.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Collection of objects?
On 17.11.2006 19:08 Donn Cave wrote: On Fri, 17 Nov 2006, Valentin Gjorgjioski wrote: ... But I need something which is heterogeneous and non-fixed length. I'm used do Java, and this switch to functional languages is very strange to me. So, to be clear, I need something like LinkedList in java. I looked in a couple of on-line tutorials, thinking I would quickly find something about this, but -- maybe in my haste I missed something. Objective CAML documentation gets right to it, I wonder if we're assuming prior exposure to strongly typed functional languages? Anyway, you need to define a type that accounts for the types you want to support - data Object = IntObject Int | StringObject String objectString :: Object -> String objectString (IntObject v) = show v objectString (StringObject v) = v main = mapM (putStrLn . objectString) [(IntObject 7), (StringObject "eight")] Donn Cave, [EMAIL PROTECTED] Thanks to all try to help me. I like the solution from Donn and Henning. I obviously not read enough. The solution is also in Yet Another Haskell Tutorial. Ok, not this much explicit, but its there. It says We have seen an example of the data type with one constructor: Pair. It is also possible (and extremely useful) to have multiple constructors(I'm shame that I even didn't know this). It's interesting that it's said EXTREMELY useful. And yes, it is! So, I think that Henning idea is good and this should go on some haskell wiki - s. Once again thanks to all for quick and nice solution. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Collection of objects?
i have cut-and-pasted the last few postings into the wiki: http://haskell.org/haskellwiki/Heterogenous_collections it'is very ad hoc, but i hope it helps those who bump into it a little. and it's easier to edit and improve than a mailing list thread. (-: matthias signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] working with lists of couples
On 17.11.2006 19:51 Valentin Gjorgjioski wrote: So, this algorithm should work fine for you buildCouples :: [Int]->Int->[(Int,Int)] buildCouples (x:[]) s = [(x,s)] buildCouples (x:xs) s = [(x,s)] ++ (buildCouples xs (x+s)). Please ignore the . at the end, it is a typo :( Sorry again... ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] working with lists of couples
On 17.11.2006 19:29 Clara Zamolo wrote: Hello, i'd like to write a function that given a list like [1,2,3,4...] returns a list of couple where the first element is the corresponding element of the string, and the second is the sum of the previous elements. An example: input: [1,2,3,4] output: [(1,0)(2,1)(3,3)(4,6)] The problem could seem trivial, and here's a first solution: buildCouples = snd . foldl op (0,[]) where op (v,xs) x = (v+x,xs++[(x,v)]) The problem is that this solution is quadratic, and I want a solution that take time n (2n is not good either). time n = time 2*n because of O(n)=O(2*n) So, this algorithm should work fine for you buildCouples :: [Int]->Int->[(Int,Int)] buildCouples (x:[]) s = [(x,s)] buildCouples (x:xs) s = [(x,s)] ++ (buildCouples xs (x+s)). buildCouples [1,2,3,4,5,6] 0 [(1,0),(2,1),(3,3),(4,6),(5,10),(6,15)] Valentin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] working with lists of couples
On Fri, 17 Nov 2006, Clara Zamolo wrote: > Hello, > i'd like to write a function that given a list like [1,2,3,4...] > returns a list of couple where the first element is the corresponding > element of the string, and the second is the sum of the previous > elements. > An example: > input: [1,2,3,4] > output: [(1,0)(2,1)(3,3)(4,6)] > > The problem could seem trivial, and here's a first solution: > > buildCouples = snd . foldl op (0,[]) >where >op (v,xs) x = (v+x,xs++[(x,v)]) > > The problem is that this solution is quadratic, and I want a solution > that take time n (2n is not good either). > > Any suggestion? I suggest using 'scanl' and then 'zip' the result together with the original list. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] working with lists of couples
Hello, i'd like to write a function that given a list like [1,2,3,4...] returns a list of couple where the first element is the corresponding element of the string, and the second is the sum of the previous elements. An example: input: [1,2,3,4] output: [(1,0)(2,1)(3,3)(4,6)] The problem could seem trivial, and here's a first solution: buildCouples = snd . foldl op (0,[]) where op (v,xs) x = (v+x,xs++[(x,v)]) The problem is that this solution is quadratic, and I want a solution that take time n (2n is not good either). Any suggestion? Thanks, Clare. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Re: [Haskell-cafe] Collection of objects?
Depending on your needs and your comfort level with fancier types, the existential approach to ADTs might solve your problem. The following code is a demonstration you can cut-and-paste-and-run. This is example akin to upcasting in Java to an interface that lets you print things. That way you know how to print every object (or do whatever else it is you need to do) in the list. Beware: there is no safe downcasting (that's what Typeable would be for); that would likely be more than you need. There are other ways to do this with existentials (e.g. bounded existentials), but this is what came out of my head when I read your post. Existentials seems to be the "Haskellish" way to reduce a hetergenous list to a collection of objects with common operations. HList would be the Haskellish way for more static and flexible assurances. {-# OPTIONS -fglasgow-exts #-} module Test where data PrintPackage = forall a . PrintPackage a (a -> String) instance Show PrintPackage where show (PrintPackage val showMethod) = showMethod val list = [ PrintPackage 3 show , PrintPackage "string" show , PrintPackage 3.4 show ] main = print list Hope that helps more than it confuses, Nick On 11/17/06, Henning Thielemann <[EMAIL PROTECTED]> wrote: On Fri, 17 Nov 2006, Valentin Gjorgjioski wrote: > Is some kind of collection of object with different types in Haskell exist? > Except the tuples, which have fixed length. > I find this > >* Tuples heterogeneous, lists homogeneous. >* Tuples have a fixed length, or at least their length is encoded in > their type. That is, two tuples with different lengths will have > different types. >* Tuples always finite. > > But I need something which is heterogeneous and non-fixed length. I'm used do > Java, and this switch to functional languages is very strange to me. So, to be > clear, I need something like LinkedList in java. > > Can you please help me or suggest me, what can I use in this case? If the number of types to cover is fixed, then I suggest a data type like data T = ConsIntInt | ConsString String | ConsChar Char Since this is a very FAQ I wonder why I don't find the answer in any of the Haskell wikis. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Collection of objects?
On Nov 17, 2006, at 12:36 PM, Valentin Gjorgjioski wrote: Is some kind of collection of object with different types in Haskell exist? Except the tuples, which have fixed length. I find this * Tuples heterogeneous, lists homogeneous. * Tuples have a fixed length, or at least their length is encoded in their type. That is, two tuples with different lengths will have different types. * Tuples always finite. But I need something which is heterogeneous and non-fixed length. I'm used do Java, and this switch to functional languages is very strange to me. So, to be clear, I need something like LinkedList in java. The thing you're looking for doesn't really exist. (OK, yes, I'm lying a bit. You can use existential types, but you probably don't actually need them, and they can get complicated quickly; they're better left until later). Can you give us more details about what you're trying to do? Readjusting your thinking patterns can be difficult, but the people on this list are usually happy to help. Can you please help me or suggest me, what can I use in this case? Valentin Rob Dockins Speak softly and drive a Sherman tank. Laugh hard; it's a long way to the bank. -- TMBG ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Collection of objects?
On Fri, 17 Nov 2006, Valentin Gjorgjioski wrote: > Is some kind of collection of object with different types in Haskell exist? > Except the tuples, which have fixed length. > I find this > >* Tuples heterogeneous, lists homogeneous. >* Tuples have a fixed length, or at least their length is encoded in > their type. That is, two tuples with different lengths will have > different types. >* Tuples always finite. > > But I need something which is heterogeneous and non-fixed length. I'm used do > Java, and this switch to functional languages is very strange to me. So, to be > clear, I need something like LinkedList in java. > > Can you please help me or suggest me, what can I use in this case? If the number of types to cover is fixed, then I suggest a data type like data T = ConsIntInt | ConsString String | ConsChar Char Since this is a very FAQ I wonder why I don't find the answer in any of the Haskell wikis. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Collection of objects?
On Fri, 17 Nov 2006, Valentin Gjorgjioski wrote: ... > But I need something which is heterogeneous and non-fixed length. I'm > used do Java, and this switch to functional languages is very strange to > me. So, to be clear, I need something like LinkedList in java. I looked in a couple of on-line tutorials, thinking I would quickly find something about this, but -- maybe in my haste I missed something. Objective CAML documentation gets right to it, I wonder if we're assuming prior exposure to strongly typed functional languages? Anyway, you need to define a type that accounts for the types you want to support - data Object = IntObject Int | StringObject String objectString :: Object -> String objectString (IntObject v) = show v objectString (StringObject v) = v main = mapM (putStrLn . objectString) [(IntObject 7), (StringObject "eight")] Donn Cave, [EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Collection of objects?
this is not exactly what you are looking for, but it contains a link to HList: http://www.haskell.org/haskellwiki/Extensible_record and then there is the follow-up work to HList, an OO library written in Haskell: http://homepages.cwi.nl/~ralf/OOHaskell/ it's quite a challenging read if you just want to go ahead and use hetero-collections, but it should give you a lot of ideas and pointers. i think there are also less type-safe alternatives in at least ghc. is Data.Typeable an interesting thing to look at? hth, matthias On Fri, Nov 17, 2006 at 06:36:30PM +0100, Valentin Gjorgjioski wrote: > To: haskell-cafe@haskell.org > From: Valentin Gjorgjioski <[EMAIL PROTECTED]> > Date: Fri, 17 Nov 2006 18:36:30 +0100 > Subject: [Haskell-cafe] Collection of objects? > > Is some kind of collection of object with different types in Haskell > exist? Except the tuples, which have fixed length. > I find this > >* Tuples heterogeneous, lists homogeneous. >* Tuples have a fixed length, or at least their length is encoded in > their type. That is, two tuples with different lengths will have > different types. >* Tuples always finite. > > But I need something which is heterogeneous and non-fixed length. I'm > used do Java, and this switch to functional languages is very strange to > me. So, to be clear, I need something like LinkedList in java. > > Can you please help me or suggest me, what can I use in this case? > > Valentin > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe -- Institute of Information Systems, Humboldt-Universitaet zu Berlin web: http://www.wiwi.hu-berlin.de/~fis/ e-mail: [EMAIL PROTECTED] tel: +49 30 2093-5742 fax: +49 30 2093-5741 office: Spandauer Strasse 1, R.324, 10178 Berlin, Germany pgp: AD67 CF64 7BB4 3B9A 6F25 0996 4D73 F1FD 8D32 9BAA ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Collection of objects?
On 11/17/06, Valentin Gjorgjioski <[EMAIL PROTECTED]> wrote: But I need something which is heterogeneous and non-fixed length. You're looking for HList: http://homepages.cwi.nl/~ralf/HList/ Kurt ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Collection of objects?
Is some kind of collection of object with different types in Haskell exist? Except the tuples, which have fixed length. I find this * Tuples heterogeneous, lists homogeneous. * Tuples have a fixed length, or at least their length is encoded in their type. That is, two tuples with different lengths will have different types. * Tuples always finite. But I need something which is heterogeneous and non-fixed length. I'm used do Java, and this switch to functional languages is very strange to me. So, to be clear, I need something like LinkedList in java. Can you please help me or suggest me, what can I use in this case? Valentin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Updated School of Expression Sources?
I downloaded the SOE sources from http://www.haskell.org/soe and found they were not compatible with the my version of WinHugs (Sep 2006). I have two questions: 1) Is an updated version of those sources available? 2) If not, would someone like to host mine? I updated all the source files so they at least load without error. Mostly it involved changing a few import statements. I also had to make some updates to the included Haskore files. Also, I found the some of the programs included crash Hugs without warning. For example, evaluating "test cball5" in the file "Fal.lhs" will crash Hugs after running for a few seconds, or if the mouse is moved over the window. Does anyone know why that may occur? Justin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re[2]: [Haskell] I18N, external strings
Hello Axel, Friday, November 17, 2006, 11:27:00 AM, you wrote: > (l_ "Translate this") > is compiled into a C string constant, that GHC then turns lazily into a > list of characters, which l_ then turns into an array in C land to pass > to the gettext function, which, in turn, returns a new C string array > that has to be turned into a Haskell string again. So I'm glad Lennart > proposed to turn String into a class which would then make it possible > to pass a pointer to a contant C string to gettext. i'm not sure that you are right. GHC can perform compile-time computation of constant expressions. Don Bruce should know better, once he pointed out how a String constant can be turned into ByteString one at compile time -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Friday Afternoon Play: The Burrows Wheeler Transformation
So, it's Friday afternoon (well, here anyway), and presumably everyone is thinking of leaving for the weekend. Is anyone interested in playing a little game? I'm going to make the first move, and then just wait and see if anyone makes the next. I'm certainly not promising to make any further moves myself, but I'm not promising I won't, either. Below you'll see a naïve implementation of the Burrows Wheeler transformation and its inverse. That's my move. (And don't complain too much about style and such -- I'm half asleep.) Further moves are made by transforming the programme so that it becomes more efficient. The first target is not raw speed, but to adjust it until the computational complexity gets to be what it should be. I'm hoping for elegant moves here. After that, folk might start replacing the lists with more efficient datastructures and so on, but still /elegantly/. The object of the game isn't ultimate speed -- I've no particular wish to see a Haskell version that's as fast as a good C version, especially not if it ends up /looking/ like a C version. Really the objective is to think about Haskell programming -- and probably come up with some observations such as "there really ought to be a class of indexable structures, so that we don't have to change (!!) to (!) all over the place". And to have fun, anyhow... * * * Demonstration of the principle of the Burrows Wheeler transform. The implementations are simplistic (and have worse complexity than is possible). > module Burrows_Wheeler_Transform where > import List This is surely the wrong module to have to find (><) from: > import Data.Graph.Inductive.Query.Monad((><)) The forward transformation. Input a list, output the transformed list and possibly an int (Nothing if there were no elements in the input -- perhaps the result type should be Maybe (NonEmptyList t,Int)) > slow_bwt:: Ord t => [t] -> ([t], Maybe Int) This version works by computing a list of all the rotations of the input and sorting it. The transformation is then the last element of each line of the sorted rotations. Tag the data with an index so that it's possible to find where the original form of the unput ends up after sorting. This is essentially the specification of the transform coded up directly. > slow_bwt l > = (map fst tagged_bwt, index_of_original) > where tagged_bwt = map (last> $ sort > $ rotations l`zip`[0..] > index_of_original = findIndex ((==0).snd) tagged_bwt that looks like worst case n²×log n to me (where n is the length of the string): if every element is the same, the n×log n comparisons the sort does will each look at every element, and that's really more than is necessary. The inverse transform. We should have that @ slow_inv_bwt . slow_bwt == id @ Observe that sorting the input gives the first column of the sorted rotations (and the input is the last). So after one sort we have X... c Y... b Z... a . .. . .. . .. Since they are rotations, rotating each row of this gives pairs that belong to the original list: cX ... by ... aZ ... . . . . . . sorting these gives us the first two columns of the sorted rotations, and again we already know the last column, which can be rotated into the first and so on. > slow_inv_bwt ([],_) = [] > slow_inv_bwt (l,Just index_of_original) > = iterate catsort (replicate len []) After (length input) iterations we have the original sorted rotations, > !! len and we have the index of where the untransformed string is, so we can just pick it back out. > !! index_of_original > where catsort s = sort $ map (uncurry (:)) $ l `zip`s > len = length l This version does rather fewer sorts: > mark2_inv_bwt ([],_) = [] > mark2_inv_bwt (l,Just n) > = (transpose $ take (length l) $ iterate (permuteWith perm) l)!!(perm!!n) > where perm = map snd $ sort $ l `zip` [0..] Should I simply have left it out and hoped that it would turn up after a few moves? I'm not going to explain it, anyway. > rotations l = init $ zipWith (++) (tails l) (inits l) > permuteWith ns l = map (l!!) ns -- Jón Fairbairn [EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Debugging partial functions by the rules
Exactly! On Nov 17, 2006, at 07:30 , Henning Thielemann wrote: It seems to me like the discussion about static typesafety vs. no or weak typesafety. (Which still exists with respect to several Haskell libraries.) Of course, all type errors can be catched also by a debugger. So was the decision of making Haskell statically type-safe only made in order to be freed of writing a debugger? Certainly not, because type checks can catch errors early and precisely, that is, better than any debugger. That's also true for DEPRECATE fromJust. Give the user a hint early, that his decision of using fromJust is shortsighted and is possibly due to unfortunate program design. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Debugging partial functions by the rules
On Fri, 17 Nov 2006, Neil Mitchell wrote: > Hi > > > > How controversial would a proposal to {-# DEPRECATE fromJust #-} be, in > > > favour of: > > > > > > Just _ = x -- which will give you the precise line number > > > > It seems to me this is one cause of mysterious newbie errors we > > > could easily discourage, with little harm. > > > > Btw, I'm not seriously suggesting removing it ;) > > It could be discouraged ever so slightly in the haddocks though. > > I strongly disagree. If we are removing things that confuse newbies > why not start with higher rank types, MPTC's and GADT's ;) > > fromJust is simple, useful and clear. What you mean is that > implementations aren't very good at debugging this. It seems unfair to > blame partial functions for the lack of a debugger. If a call stack > was automatically output every time a fromJust failed would this even > be something people complained about? It seems to me like the discussion about static typesafety vs. no or weak typesafety. (Which still exists with respect to several Haskell libraries.) Of course, all type errors can be catched also by a debugger. So was the decision of making Haskell statically type-safe only made in order to be freed of writing a debugger? Certainly not, because type checks can catch errors early and precisely, that is, better than any debugger. That's also true for DEPRECATE fromJust. Give the user a hint early, that his decision of using fromJust is shortsighted and is possibly due to unfortunate program design. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Debugging partial functions by the rules
Hi > How controversial would a proposal to {-# DEPRECATE fromJust #-} be, in > favour of: > > Just _ = x -- which will give you the precise line number > It seems to me this is one cause of mysterious newbie errors we > could easily discourage, with little harm. Btw, I'm not seriously suggesting removing it ;) It could be discouraged ever so slightly in the haddocks though. I strongly disagree. If we are removing things that confuse newbies why not start with higher rank types, MPTC's and GADT's ;) fromJust is simple, useful and clear. What you mean is that implementations aren't very good at debugging this. It seems unfair to blame partial functions for the lack of a debugger. If a call stack was automatically output every time a fromJust failed would this even be something people complained about? Thanks Neil ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Debugging partial functions by the rules
On Fri, 17 Nov 2006, S. Alexander Jacobson wrote: > As long as we are doing this, perhaps we should also discourage the use of > (head list)? Is 'cycle' also bad style, because it fails on empty lists? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] 'type' for isomorphism [was poorly named: aggressiveness of functional dependencies]
Hello Nicolas, Friday, November 17, 2006, 1:17:30 AM, you wrote: > So it works, but it wasn't quite what I had hoped for. Has there been > any work/proposals for specifying a "finalized" type class? I.E. Those > not subject to overlap and thus "closed" to the world? it is a common idea, at least i had it and seen John Meacham's proposal reasons mainly falls into two categories: 1) optimization: this allows compiler to make final decisions and inline appropriate code instead of be ready for some new instances that will change the whole game 2) with closed class, compiler may be smarter about overlapping, type deriving and other type checking/inferring procedures -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Generalizing zip
Jón Fairbairn <[EMAIL PROTECTED]> writes: > "Jason Dagit" <[EMAIL PROTECTED]> writes: > > > Well, this is basically just a zip with a special base case. But you > > [...] > I wonder if there is mileage to be had from persuing > something like this, rather different (off top of head, very > provisional, E&OE &c) approach: > >extend_infinitely l = map Just l ++ repeat Nothing >promote1 rel (Just a) b = rel a b >promote1 rel Nothing b = False >is_pfx_of l1 l2 = and (zipWith (promote1 (==)) (extend_infinitely l2) l1) or, possibly better extend_infinitely l = map Just l ++ repeat Nothing is_pfx_of l1 l2 = and (zipWith (==) (extend_infinitely l2) (map Just l1)) -- Jón Fairbairn [EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe