[Haskell-cafe] Re: APIs (was: Unexported functions are evil)
G'day all. Quoting Graham Klyne <[EMAIL PROTECTED]>: > I think you raise an important point. Reading this, I realize that I have > no principled basis for deciding what makes a good API, in any language. Me neither. Though I have short reading list. First off, this series of articles by Ken Arnold. They are a bit Java- centric, but it's all good: http://www.artima.com/intv/perfect.html http://www.artima.com/intv/taste.html http://www.artima.com/intv/distrib.html http://www.artima.com/intv/sway.html http://www.artima.com/intv/decouple.html http://www.artima.com/intv/issues.html Some of the modern C++ books like "Modern C++ Design" and "Generative Programming" are worth a skim in lieu of a decent book on how to deal with true parametric polymorphism and typeclasses. Oh, if you can get a copy of "Software Fundamentals" (the collection of Parnas papers), do it. It's a fabulous read, even if you don't get much in the way of API design out of it. Cheers, Andrew Bromage ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Data types and Haskell classes
On Tue, May 17, 2005 at 01:13:17PM +0200, Jens Blanck wrote: > > > How would I introduce number classes that are extended with plus and > > > minus infinity? I'd like to have polymorphism over these new classes, > > > something like a signature > > > > > > f :: (Real a, Extended a b) => b -> b > > > > > > which clearly is not part of the current syntax, but I hope you get > > > the picture. What are the elegant ways of doing this? > > > > How about > > f :: Real a => Extended a -> Extended a > > Not quite what I had in mind. I'd like to have extended integers and > extended rationals, and possibly extended dyadic numbers. So I can't > have just a single type ExtendedRational (unless I'm prepared to do > some ugly coersing). You're missing the point. Try: > data Extended a = PlusInf | NegInf | Finite a Peace, Dylan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] www.haskell.org
I'm trying to download a darcs client, but I get: "The connection was refused when trying to connect to www.haskell.org" from Firefox on Linux. -- Colin Adams Preston Lancashire ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Bit fiddling
Hello, There is also Hal Daume III's port of Binary from nhc98 which has some bit-fiddling features: http://www.n-heptane.com/nhlab/ Not sure if it is better than any of the other suggestions, but I thought I would mention it just in case. (note: the debian directory in there is unofficial for now, possibly broken, and the source / binary package names it generates will be changing soon. But the cabal stuff is reasonably up-to-date.) Jeremy Shaw. At Wed, 18 May 2005 12:05:02 +0400, Bulat Ziganshin wrote: > > Hello Florian, > > Wednesday, May 18, 2005, 12:44:14 AM, you wrote: > > FW> I'm toying a bit with Haskell and wondering what's the best way to > FW> implement bit fiddling. Most of my applications involve serializing > FW> and deserializing small blobs (IP packets, for instance), and after > FW> browsing the GHC library documentation, I'm not sure which appraoch I > FW> should use. That's why I'd appreciate pointers to sample code. > > you can find Binary.hs in the GHC 6.4 sources (sources of compiler > itself) and close to this ByteStream library on my page > http://freearc.narod.ru > > with help of my library all you need to deserialize data is just: > > (sign::Word32, block_type::Int16, crc::Word64) <- ByteStream.readMemory buf > bufsize > > there is no such easy serialization, i just don't need it because my > program uses only low-level functions, but i can add for you > something like: > > (buf,bufsize) <- ByteStream.writeMemory (sign, block_type, crc) > > > > -- > Best regards, > Bulatmailto:[EMAIL PROTECTED] > > > > ___ > 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] Python?
Bjorn Lisper wrote: Hi all, Finally I found some time to reply to this posting. A couple of years ago we did something called "Data Field Haskell", which is Haskell extended with a generalized form of arrays called data fields. Much of the purpose was to investigate convenient and general syntax for array constructions. ... The forall-construct is intended to provide a simple and powerful syntax for operations on data fields. Let's see below how it matches Jerzy's desired features of an array language: ... I AM IMPRESSED. Now, I know the existence of pages within http://www.mrtc.mdh.se/projects/DFH/ but you say that the project is dormant. Is there *anything* going on? THANKS! Jerzy Karczmarczuk ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] APIs (was: Unexported functions are evil)
> I think you raise an important point. Reading this, I realize that I have > no principled basis for deciding what makes a good API, in any language. I > do, of course, have lots of personal ideas and feelings about what APIs > should be like, but not that I could defend as coherent and rational strategy. > > So I ask myself: are there any good papers or books on this topic that > outline a coherent and principled approach to API design? if you like the historical approach, you could start with David Parnas On the Criteria To Be Used in Decomposing Systems into Modules http://www.acm.org/classics/may96/ then look for papers that reference this one. see also the interview http://www.acm.org/sigsoft/SEN/parnas.html for how he came to start thinking about interfaces and information hiding. cheers, claus ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Python?
On Wed, 18 May 2005, Bjorn Lisper wrote: forall (i,j) -> i + j, a Vandermonde matrix This does not look like a Vandermonde http://mathworld.wolfram.com/VandermondeMatrix.html If you take reciprocals you obtain almost a Hilbert matrix. http://mathworld.wolfram.com/HilbertMatrix.html ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Python?
Hi all, Finally I found some time to reply to this posting. A couple of years ago we did something called "Data Field Haskell", which is Haskell extended with a generalized form of arrays called data fields. Much of the purpose was to investigate convenient and general syntax for array constructions. Data fields are semantically pairs of functions and bounds, where bounds represent sets of indices. Bounds can be pairs of integers representing intervals, but also general finite sets. Certain bounds represent infinite sets, which makes sense in a lazy language. Besides direct notation for creating data fields, Data Field Haskell has a construct "forall x -> t" which defines a data field in a similar way to how lambda-abstraction \x -> t defines a function. In addition, the data field defined by a forall-construct has a bound which is derived from the body of the expression. The semantics is derived from the view that data fields (and arrays) are partial functions whose domains do not exceed the index sets defined by their bounds. The forall-construct is intended to provide a simple and powerful syntax for operations on data fields. Let's see below how it matches Jerzy's desired features of an array language: Jerzy: >Tim Rowe writes: > >> On 5/11/05, Jerzy Karczmarczuk <[EMAIL PROTECTED]> wrote: >> >>> Give me one single language where [3-d arrays are] natural and immediate. >> >> I don't know how Matlab does it, but I find the C++ standard library >> vector > > >> entirely intuitive (apart, perhaps, for the need for those two spaces)! > >Let's precise what I consider to be important in order to call it natural >and immediate. And, in general, useful. > >1. The definition of a concrete object, not just its type, but, say, > the initialization with constants. Or/and, global initialization with > zeros. Since Data Field Haskell is declarative, initialization and definition is the same. Constant data fields are easy to define, viz. forall x -> 1, a data field filled with ones forall (i,j) -> if i == j then 1 else 0, a unit matrix forall (i,j) -> i + j, a Vandermonde matrix All these data fields are infinite, and the first is also dimension-polymorphic (through the usual polymorphism in Haskell). Data Field Haskell has an operator for explicit restriction of data fields, and a data field may also be implicitly restricted from the context where it occurs. >2. Easy synthesis of multi-dim matrices out of "planes", of submatrices > of lesser dimensions; Not directly expressible, but it is possible to define a binary operator to, say, concatenate a 2-D matrix on some given "side" of a 3-D matrix. > it can be an 'overlay', like, say, making a colour image out of three > R/G/B planes, or making a 3D surfaces, or aking tensors through > external products. Say, an outer product of two vectors a, b: forall (i,j) -> a!i * b!j >3. Easy indexing, and not only A[i][j][k], etc., but slicing, the extraction > of sub-dimensional matrices, e.g., one column vector out of a 2D matrix > in Matlab: A(3,:). Also, extracting parts (e.g. sub-images). A(3,:) is expressed as forall j -> a!(3,j). Or, selecting a plane out of a 3D-matrix: forall (i,j) -> a!(i,3,j). Or, selecting the main diagonal of a matrix: forall i -> a!(i,i). Extracting parts is done with the explicit restriction operator <\>: a <\> (3,3)<:>(10,20), selecting submatrix of a a <\> predicate (\(i,j) -> a!(i,j) > 0), selecting the subfield of a where it is strictly greater than zero (this is a sparse data field) > Also, in mathematical context, "intelligent" indexing, e.g. treating > a matrix as implicitly anti-symmetric. Here the CAS systems as Maple > or Mathematica provide the adequate tools. C++ of course doesn't, > unless you overload [] yourself. All representation issues are hidden in Data Field Haskell, so there is no direct counterpart. However, it is of course possible to define a data structure of your own and then wrap it up as a data field by providing a bound and a function from indices to values. >4. Readable iterators, perhaps something more compact than insipid do-loops. There are folds for data fields. These can be used for reduction operations over data fields. In a sense, forall-abstraction is also a kind of iterator (although "parallel" since it does not impose any order of evaluation between the elements of the data field). >5. If those matrices are used as mathematical objects: tensors, etc., > I want to have some simple notation for inner multiplications/ > contractions, etc. This is not just the syntax problem, but the > existence of good libraries as well... You can use folds "inside" a matrix to, e.g., sum all rows in a matrix. Here is an example of a function that does one iteration in Jacobi's method for iteratively solving the linear equation system ax = b: jacobi_iter a b x = forall i -> ((b!i) - dfSum ((forall j -> a!(i,j)*(x!j)) <\> predicate (\j -> j /= i)))
[Haskell-cafe] APIs (was: Unexported functions are evil)
At 21:42 15/05/05 -0400, [EMAIL PROTECTED] wrote: Continuing on from the previous thought, part of the problem here is that we teach people to write code (e.g. how to implement a sort), but we don't teach people to write APIs. APIs are both trickier to get right AND are more important in larger programs. I think you raise an important point. Reading this, I realize that I have no principled basis for deciding what makes a good API, in any language. I do, of course, have lots of personal ideas and feelings about what APIs should be like, but not that I could defend as coherent and rational strategy. So I ask myself: are there any good papers or books on this topic that outline a coherent and principled approach to API design? #g Graham Klyne For email: http://www.ninebynine.org/#Contact ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Bit fiddling
Hello Florian, Wednesday, May 18, 2005, 12:44:14 AM, you wrote: FW> I'm toying a bit with Haskell and wondering what's the best way to FW> implement bit fiddling. Most of my applications involve serializing FW> and deserializing small blobs (IP packets, for instance), and after FW> browsing the GHC library documentation, I'm not sure which appraoch I FW> should use. That's why I'd appreciate pointers to sample code. you can find Binary.hs in the GHC 6.4 sources (sources of compiler itself) and close to this ByteStream library on my page http://freearc.narod.ru with help of my library all you need to deserialize data is just: (sign::Word32, block_type::Int16, crc::Word64) <- ByteStream.readMemory buf bufsize there is no such easy serialization, i just don't need it because my program uses only low-level functions, but i can add for you something like: (buf,bufsize) <- ByteStream.writeMemory (sign, block_type, crc) -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe