Re: [Haskell-cafe] Wanted: Haskell binding for libbdd (buddy)

2012-08-20 Thread Peter Gammie
On 20/08/2012, at 11:19 PM, Johannes Waldmann wrote:

 Are there any Haskell bindings for BDD libraries
 (reduced ordered binary decision diagrams)?
 
 E.g., it seems buddy is commonly used
 http://packages.debian.org/squeeze/libbdd-dev
 and it has an Ocaml binding.

My hBDD bindings are on Hackage. I once had a binding to buddy but found CUDD 
to have superior performance for my application.

cheers
peter

-- 
http://peteg.org/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Why does (++ !) bla return bla! and not !bla?

2012-06-21 Thread Peter Gammie
Hilco,

On 22/06/2012, at 2:54 PM, Hilco Wijbenga wrote:

 I'm going through the excellent http://learnyouahaskell.com tutorial.
 So far it's been pretty easy to follow but now I ran into something
 that (when I later started reading about maps) do not seem to fully
 grasp.
 
 I think I'm close to understanding why (++ !) bla returns bla!
 instead of !bla but I seem to be missing the last step. :-) I
 noticed that ((++) !) bla does indeed return !bla. So it seems
 to be related to the infix property of ++? The types of (++) !,
 ((++) !), and (++ !) are all the same so that doesn't tell me
 much.

This stuff is in a beginner's tutorial? (!?)

This is purely a syntactic issue. These things are called sections.

It might be more obvious if we put in some lambda abstractions, which I hope 
your tutorial has already introduced:

(++ !) = (\x. x ++ !)
(! ++) = (\y. ! ++ y)

Yes, it is related to the infix property of ++. You can get similar things 
going with arbitrary binary (two argument) functions like so:

app = (++) -- or whatever

(`app` !) = (\x. x `app` !) = (\x. app x !)
(and the other way around)

cheers
peter

-- 
http://peteg.org/


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Theoretical question: are side effects necessary?

2012-03-16 Thread Peter Gammie
Christopher,

On 16/03/2012, at 11:23 PM, Christopher Svanefalk wrote:

 there is a question I have been thinking about a bit. In short, we could 
 simply formulate it like this:
 
 Are there any problems which cannot be solved a side effect-free language 
 (such as Haskell)? In other words, are there problems that would explicitly 
 demand semantics that can only be provided by a language allowing direct 
 modification of external state variables, such as Java and C++?
 
 If not, are there problems which are simply infeasible to solve with a side 
 effect-free language?

Start here:

http://www.cs.ox.ac.uk/people/geraint.jones/morehaste.html

and dig through their references.

I don't think a logarithmic factor is ever going to make the difference 
between feasible and infeasible. :-)

cheers
peter

-- 
http://peteg.org/


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Functor in terms of Arrow

2012-02-18 Thread Peter Gammie
Tom,

On 19/02/2012, at 3:21 AM, Tom Schouten wrote:

 Does AFunctor below have a standard name?  It's a generalization of
 the Functor class in terms of Arrow instead of (-):
 
  fmap  :: Functor f   = (i - o) - f i  -  f o
  afmap :: Arrow a, AFunctor f = a i o- a (f i) (f o)
 
 It pops up in less general form (AFunctor = []) in iterated functions
 (difference equations / state space models), where the arrow is the
 update function parameterized by state type:
 
  data Iter s i o = Iter ((s,i) - (s,o))
  instance Arrow (Iter s)

I think you can work with Arrow transformers instead. See:

http://hackage.haskell.org/packages/archive/arrows/latest/doc/html/Control-Arrow-Transformer-Stream.html#t:StreamArrow

It may be that you can generalise to arbitrary functors, but satisfying the 
Arrow laws may require some care.

cheers
peter

-- 
http://peteg.org/


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Question: Lazy Incremental Evaluation and Haskell?

2011-10-06 Thread Peter Gammie
Ben,

On 07/10/2011, at 8:55 AM, Benjamin Redelings I wrote:

 My question is, roughly, is there already an existing framework for 
 incremental
 evaluation in Haskell?

Margnus Carlsson did something monadic several years ago.

http://dl.acm.org/citation.cfm?doid=581478.581482

Perhaps there is an implementation on Hackage or on his website.

This stuff also goes by the moniker adaptive computation. See the references 
and citations of that paper for more on this.

cheers
peter

-- 
http://peteg.org/


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Is Harper right that Haskell cannot model the natural numbers?

2011-05-02 Thread Peter Gammie
On 03/05/2011, at 1:25 PM, Richard O'Keefe wrote:

 In one of his blog posts, Robert Harper claims that the natural numbers
 are not definable in Haskell.
 
 SML   datatype nat = ZERO | SUCC of nat
 Haskell   data Nat = Zero | Succ Nat
 
 differ in that the SML version has strict constructors, and so only
 finite instances of nat can be constructed, whereas Haskell has
 lazy constructors, so
   inf = Succ inf
 is constructible, but that's not a natural number, and it isn't
 bottom either, so this is not a model of the natural numbers.
 
 Fair enough, but what about
 
   data Nat = Zero | Succ !Nat
 
 where the constructors *are* strict?  It's perfectly good Haskell 98
 as far as I can see.  Now Nat itself isn't _quite_ a model of the
 naturals because it includes bottom, but then an SML function
 returning nat can also fail, so arguably SML's nat could or should be
 thought of as including bottom too.
 
 What am I missing?

Do read the comments attached to the blog post (and also maybe at reddit).

I believe the traditional model for ML-like languages  in denotational 
semantics is to lift the type returned by a function. So ML's Nat type is 
taken to be an inductively-defined set (with the discrete order) and your 
divergent ML function really has type a - Nat_{lift} for whatever type a you 
had in mind. I think Moggi's encoding into monads makes this clear - you use 
the Maybe/Evaluation/Strict monad to handle divergent arguments.

cheers
peter

-- 
http://peteg.org/


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to keep cabal and ghci package versions in sync?

2011-04-26 Thread Peter Gammie
On 27/04/2011, at 3:04 AM, Rogan Creswick wrote:

 At the moment, cabal-dev ghci just uses the -package-conf and
 -no-user-package-conf flags to restrict ghci to the sandboxed and
 global package dbs.
 
 It's difficult to do more without parsing the content of the project's
 cabal file, and that parser isn't exposed through a library api (it's
 in cabal-install), which makes it a little difficult to use.

Can't you use cabal as a library to do this?

I had a crack at figuring out a ghci command line in TBC (testing by 
convention):

https://github.com/peteg/TBC

while waiting for this cabal feature to be implemented:

http://hackage.haskell.org/trac/hackage/ticket/382

Apparently there's a GSoC project that will nail this.

You can fire up TBC with the verbose flag and it will give you a very long ghc 
invocation line that is strongly similar to what cabal uses to compile your 
project. It doubtlessly is incomplete, and probably bit rotten. I will try to 
make it work with the latest Haskell Platform release in the coming weeks.

I welcome patches, but you're better off fixing cabal itself.

cheers
peter

-- 
http://peteg.org/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Asynchronous Arrows need Type Specialization - Help!

2011-03-22 Thread Peter Gammie
David,

On 21/03/2011, at 4:18 PM, David Barbour wrote:

 I was giving Control.Arrow a try for a reactive programming system.
 The arrows are agents that communicate by sending and returning
 time-varying state. Different agents may live in different 'vats'
 (event-driven threads) to roughly model distributed computing. For the
 most part, the state varies asynchronously - i.e. a file updates at a
 different rate than the mouse position. Anyhow, I ran into a problem:
 The (***) and () operations, as specified in Control.Arrow, are
 inherently synchronization points.

Indeed. Take a look here:

http://www.haskell.org/haskellwiki/Research_papers/Monads_and_arrows#Arrows

In particular, ProdArrows -- Arrows for Fudgets by Magnus Carlsson.

cheers
peter

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] lambda calculus and equational logic

2010-07-13 Thread Peter Gammie
Ben, comments from the peanut gallery:

On 13/07/2010, at 11:51 PM, Ben Lippmeier wrote:

 What kind of equality do you use for  getChar :: IO Char ?

Surely this is easy: getChar denotes a particular IO action, which is always 
the same thing (i.e. self-identical and distinct from all other IO actions).

 By massively complicated you mean harder than the simplest case. 
 Haskell's do-notation makes the state of the world implicit, and performing 
 the desugaring makes it explicit again -- but then that state isn't really 
 the state of the word...

... which tells you that the passing-the-world semantics is not a faithful 
model of I/O.

In the archives of this list there are many comments on exactly this topic. A 
couple of quick pointers:

- Wouter Swierstra wrote a paper on this.

http://www.cse.chalmers.se/~wouter/repos/IOSpec/index.html

- Resumptions are a better model:

http://www.haskell.org/pipermail/haskell-cafe/2003-August/004892.html

Intuitively the state monad used by GHC works because it only needs to track 
dependencies between I/O actions - there is no need for the compiler to impose 
a total order on everything going on in the world (taken to be all of the 
context that could influence the execution of the program). For interesting 
programs it cannot, anyway.

cheers
peter

-- 
http://peteg.org/

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: FRP for game programming / artifical life simulation

2010-04-28 Thread Peter Gammie
Ben,

On 29/04/2010, at 6:16 AM, Ben wrote:

 [...]
 
 newtype STAuto s a b = STAuto { unSTAuto : (a, s) - (b, s) }

As Felipe observes in detail, this can be made to work. He uses Read and Show 
for serialisation, but clearly you can use whatever you like instead.

I just wanted to add that one can go to town with the approach: after you 
understand Felipe's stuff, take a look at Caspi and Pouzet's coalgebraic 
streams stuff. (I'd recommend looking at both the tech report and the published 
paper, and there is some Haskell code too.)

BTW I was referring (off-list) to the original Arrows paper by John Hughes.

cheers
peter

-- 
http://peteg.org/

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Bulk Synchronous Parallel

2010-04-21 Thread Peter Gammie
On Thu, Apr 22, 2010 at 4:07 AM, Aaron D. Ball
aarondball+hask...@gmail.com wrote:

 I don't need a tool that automatically figures out how to distribute
 any workload in an intelligent way and handles all the communication
 for me.  If I have the basic building block, which is the ability to
 serialize a Haskell expression with its dependencies and read them
 into another Haskell instance where I can evaluate them, I can handle
 the other pieces, which are

 - passing strings back and forth in whatever way is convenient
 - deciding how to divide up my workload.

Alice/ML is the place to look for this technology.

http://www.ps.uni-saarland.de/alice/

The project may be dead (I don't know), but they did have the most
sophisticated take on pickling that I've seen. It's an ML variant,
with futures, running on top of the same platform used by Mozart/Oz of
CTM fame.

Why do you want to pass strings around?

cheers
peter
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Beginning of a meta-Haskell [was: An issue with the ``finally tagless'' tradition]

2009-09-24 Thread Peter Gammie

Thanks Oleg!

Brad:

On 24/09/2009, at 3:54 PM, o...@okmij.org wrote:


and interpret it several times, as an integer


-- testpw :: Int
testpw = (unR power) (unR 2) ((unR 7)::Int)
-- 128


My type function allows one to remove the '::Int' annotation, which is  
especially useful in situations where you cannot give an annotation  
due to 'show . read'-style ambiguity. Conversely one gives up some  
useful polymorphism (in my case, sometimes it would be nice to have  
multiple boolean types).


Another nit with Oleg's code is that you can only interpret Bool with  
Bool, in the interpreter:



class QBool repr where
   true, false :: repr Bool
   if_ :: repr Bool - repr w - repr w - repr w


If 'repr' is merely a Haskell98-style type constructor, it cannot  
analyse its argument. Hence there are two choices: use the argument  
(Bool) or don't (see the pretty printer). I doubt you could implement  
a very pleasant interpreter using the latter option, but see


http://web.cecs.pdx.edu/~brianh/talks/talk20081010.pdf

if you want to try. Again, using a type function here allows you to  
choose an arbitrary type to represent Bool (and so forth). Trying to  
do this with fundeps is possible but syntactically heavy.


cheers
peter
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] An issue with EDSLs in the ``finally tagless'' tradition

2009-09-23 Thread Peter Gammie

Brad:

On 24/09/2009, at 11:59 AM, excerpts of what Brad Larsen wrote:


We then try to define an evaluator:


-- instance PolyArithExpr E where
--   constant   = E
--   addP e1 e2 = E (eval e1 + eval e2)  -- bzzt!


The instance definition for `addP' is not type correct:
   Could not deduce (Num a) from the context ()
 arising from a use of `+' at /home/blarsen/mail.lhs:42:20-36

One way to remedy this is to change the class definition of
PolyArithExpr so that `addP' has a Num constraint on `a':


class PolyArithExprFixed exp where
 pae_constant :: a - exp a
 pae_add  :: Num a = exp a - exp a - exp a


which allows us to define an evaluator:


instance PolyArithExprFixed E where
 pae_constant = E
 pae_add e1 e2 = E (eval e1 + eval e2)


I find this ``fix'' lacking, however: to define a new interpretation
of the EDSL, we may be forced to change the DSL definition.  This is
non-modular, and seems like an instance of the expression
problem. (There may be a multiparameter type class solution for this.)


A better fix is to shift the type constraint to the class head, e.g.:

class PolyArithExprFixed exp a where
  pae_constant :: a - exp a
  pae_add :: exp a - exp a - exp a

then:

instance PolyArithExprFixed E Integer where
...

or if you want to be more general:

instance Num n = PolyArithExprFixed E n where
...

but note that this instance precludes any other ones for  
PolyArithExprFixed without allowing overlapping instances and hence  
some Olegs / Olegging.


See, e.g.:

http://www.soi.city.ac.uk/~ross/papers/fop.html

(the slides link)

Ambiguity is IMHO best handled with a judicious application of type  
(or data) families, but you can get surprisingly far by simply  
requiring that every class member mention all type variables in the  
class head. YMMV of course.


cheers
peter
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] An issue with EDSLs in the ``finally tagless'' tradition

2009-09-23 Thread Peter Gammie

Brad,

On 24/09/2009, at 2:45 PM, Brad Larsen wrote:

On Thu, Sep 24, 2009 at 12:22 AM, Peter Gammie pete...@gmail.com  
wrote:

[...]

Ambiguity is IMHO best handled with a judicious application of type  
(or
data) families, but you can get surprisingly far by simply  
requiring that
every class member mention all type variables in the class head.  
YMMV of

course.


Can you say more about the use of type/data families?


Multi-parameter type classes generally lead to ambiguity - see the  
classic paper(s) by Simon PJ et al for some good examples.


In the context of Arrows, I used type/data families to make the  
representation type (e.g. Integer) a function of the arrow (e.g. a  
direct semantics), which makes life a bit easier for using this stuff  
but is not completely faithful to what I wanted. (Imagine you want to  
mix Integer and Double in the same expression.)


Hope this helps!

cheers
peter

--
http://peteg.org/

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: [Haskell] Re: 20 years ago

2009-07-27 Thread Peter Gammie

On 28/07/2009, at 11:35 AM, Richard O'Keefe wrote:


It's true that the abstract speaks of a more biological
scheme of protected universal cells interacting only through
messages that could mimic any desired behavior, but that's
basically _it_ for biology, if we are to believe Kay, and
even then, its semantics are a bit like having thousands of
and thousands of comptuers all hooked together by a very fast
network and Philosophically, Smalltalk's objects have much
in common with the monads of Leibnitz (bringing us neatly
back to Haskell (:-)).


But Richard (or am I arguing with Kay?) - monads don't interact.

http://en.wikipedia.org/wiki/Monadology

I'd take that to be their defining characteristic - Leibniz is trying  
to overcome Cartesian mind/body dualism here.


Perhaps Smalltalk objects are regulated by pre-established  
harmonies... and have no need to talk to each other. Or perhaps that  
is the part that lies outside Kay's identification, in which case one  
might say the ontologies of monads and Smalltalk have superficial  
similarities but the deeper structure diverges significantly. (I think  
my point is well-defended by the above wikipedia article - the OO  
insights are thin on the ground, and are at least quite tangled.)


How are you going to relate Leibniz's monads and Haskell's? I can't  
find my way, neatly or otherwise. :-P


Ah, I see, Haskell has an interface to the best of all possible  
worlds... :-)


cheers
peter

--
http://peteg.org/

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: [Haskell] Re: 20 years ago

2009-07-27 Thread Peter Gammie

On 28/07/2009, at 12:59 PM, Richard O'Keefe wrote:


On Jul 28, 2009, at 2:25 PM, Peter Gammie wrote:


But Richard (or am I arguing with Kay?) - monads don't interact.


You're arguing with Alan Kay here:  the reference to Leibniz
was his.  The key link here is (Wikipedia):  Leibniz allows
just one type of element in the build of the universe (sic.).
In precisely the same way, Alan Kay allowed just one kind of
'thing' in his computational universe: object.  Just as in
the lambda calculus, everything is a function and in set theory
everything is a set, so in Smalltalk _everything_ (including
classes and the number 42 and anonymous functions) is an object.


Yea gods, that's the thinnest use of monads ever. The concept that  
lead to idealism, away from mind-body dualism is reduced to ...  
monism. Awesome.


http://en.wikipedia.org/wiki/Monism

He could've cited just about any of the major philosophies for that -  
and I'm not going to talk about religions.


How are you going to relate Leibniz's monads and Haskell's? I can't  
find my way, neatly or otherwise. :-P


Verbally.


Sure, but I was hoping you'd explain why Wadler uses the pineal gland  
allusions in his COMPREHENDING MONADS (capitals denoting paper title).  
That structure was *exactly* what Leibniz was doing his best to avoid  
in his monadology.


I think Wadler was making a joke.

cheers
peter
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] TBC: Testing By Convention

2009-07-26 Thread Peter Gammie

Hello,

Mark and I would like to announce our test harness, which has features  
complementary to existing harnesses.


TBC provides two main features:
- It attempts to compile and run all tests, even if some do not  
compile or run.
- Aspiring to the write-it-once principle, tests following conventions  
require a lot less boilerplate.


It is at an embryonic stage of development, and would greatly benefit  
from feedback and/or patches. :-)


Hackage: http://hackage.haskell.org/package/TBC
git: http://github.com/peteg/TBC/

Enjoy!

cheers
peter

--
http://peteg.org/

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] TBC: Testing By Convention

2009-07-26 Thread Peter Gammie

On 27/07/2009, at 2:26 PM, Alexander Dunlap wrote:


Can it return an exit status based on whether or not all tests passed?
If not, that would be a very useful feature that I have not seen in
any other testing frameworks.


It could, and that's probably true of the other harnesses out there.

The git repo for TBC now has this feature; it's a bit of a hack as  
some of the functions in Cabal that TBC uses have overly restrictive  
types.


cheers
peter
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] [ANNOUNCE] Bindings for libguestfs

2009-05-13 Thread Peter Gammie

Richard,

I remember having similar problems to you when trying to use the FFI.  
The following comments are suggestions as to what helps in practice,  
and not a claim that the situation can't be improved.


On 13/05/2009, at 8:40 PM, Richard W.M. Jones wrote:


Specific things would be:

Recommendation to use 'throwDyn' to throw exceptions, yet this
function doesn't exist in my version of GHC.  In fact, none of the
code here:

http://www.haskell.org/haskellwiki/FFICookBook#Raising_and_handling_exceptions

works in GHC at all, as far as I could tell.


The shifting exceptions story is a PITA. Compatibility is the price of  
progress.



No good examples available on how to use ForeignPtr.  Yet I'd argue
that almost any non-trivial modern C library bindings will have some
concept of an opaque object, so this is the most vital example.  (The
examples in RWH ch 17 weren't enough for me).


I'd suggest you download a mature library binding close to what you  
want to do and ape that. For example:


1. got lots of C structures? look at a GTK binding.
2. got a fairly imperative API? look at a database binding, or HOpenGL.
3. got a fairly pure API? look at a BDD or numerical package binding.

and so forth.

The FFI itself is intended to be minimal, just enough to do the job.  
The idea was that extra tools (most prominently hsc2hs and c2hs,  
historically greencard) would support large bindings.


It's funny you say opaque object. ForeignPtr only handles pointers.  
In one library I relied on, the opaque objects were represented with  
ints. It'd be nice to track arbitrary values the way that ForeignPtr  
tracks C pointers.



I'd really like to know what parameters and return types are
permissible for 'foreign import ccall' statements.  By trial and error
I found out.


Is the FFI spec unclear on this point?


How do I convert to/from booleans?


Can you use the methods of the Enum class?


How do I really use C structures?  Real examples, please.


I'd suggest looking into c2hs. Even if you don't use it, the code it  
generates is quite illuminating, especially how it pushes values  
between C and Haskell.



How can I free a C string that is returned from a 'caller frees' C
function?  Does Foreign.Marshall.Alloc.free work for this?


This is tricky. Rather than give you a definite answer, I'd suggest  
you check with the FFI spec.


IIRC in principle the FFI's malloc/free could be distinct from those  
in C land, but in practice (GHC) they coincide.



Again, reflecting my own inexperience with Haskell, I found
'withCString', 'maybeWith', 'withMany', 'withArray0' etc to be both
undocumented and extremely confusing to use.


They're documented in the FFI spec. Granted using them is not  
necessarily intuitive, which is where looking at existing code might  
help.



How do I specify a 64 bit int?  Using 'Int64#' just causes syntax
errors.


Did you look into the Data.Word library?


What's a good emacs editing mode for Haskell code?  My emacs thinks
Haskell code is LISP ...


There's been a Haskell mode for at least a decade now. It's packaged  
with every emacs I've used in the past few years.


http://www.haskell.org/haskell-mode/

To editorialise a bit, I think the original FFI spec is very clearly  
written, and the contradictions you allude to lie in fact in the more  
recent wiki writeups; the Haskell specs are lucid and intended to be  
usable, and not just by the compiler writers.


One last gotcha: be very careful about strictness if you're trying to  
graft a pure API onto the library.


Hope this helps!

cheers
peter
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Problems with Validate from HaXML

2008-06-12 Thread Peter Gammie
Hello,

I have the same problems. I believe I sent Malcolm some patches. If
not, look here:

http://peteg.org/haskell/HaXml/

I am away from my laptop right now so I cannot readily tell you
whether a darcs get will do the job. In any case, there is a bug in
the DTD parser that is easily fixed. (Try downloading the Parser.hs
file if the darcs get fails.)

Hope that helps.

cheers
peter

On 6/12/08, Samuel Silva [EMAIL PROTECTED] wrote:
 Hello

 I'm working with large DTDs from http://www.recordare.com/dtds/,
 particulary partwise.dtd and timewise.dtd.
 I check these DTDs with some tools, like Altova XML Spy and Microsoft
 Visual Studio, and DTDs are valid.
 However Validate tool from HaXML doesn't validate same DTDs.
 Result from Validate is:
 $ Validate partwise.dtd
 Validate: In a sequence:
  in content spec of ELEMENT decl: note
  When looking for a non-empty sequence with separators:
Expected % but found |
in file note.mod  at line 51 col 45
  used by  file partwise.dtd  at line 120 col 1
  when looking for a content particle
  when looking for a content particle

 Problematic definition is in note.mod file, presented below:
 !ELEMENT note
(((grace, %full-note;, (tie, tie?)?) |
  (cue, %full-note;, duration) |
  (%full-note;, duration, (tie, tie?)?)),
 instrument?, %editorial-voice;, type?, dot*,
 accidental?, time-modification?, stem?, notehead?,
 staff?, beam*, notations*, lyric*)

 I'm trying using DtdToHaskell tool from HaXML to build parser from
 MusicXML to Haskell types.
 There are other ways to build XML parser using HaXML?
 I'm already using HaXML, with HaXML combinators, to write MusicXML.

 Thanks.

 --
 Don't hug that, Hugs ME!
 Samuel Silva
 ___
 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: What is the maturity of Haskell Web Frameworks

2008-06-05 Thread Peter Gammie

On 05/06/2008, at 5:31 PM, apfelmus wrote:

WASH/CGI has something in that direction. I don't know a short  
introduction, but have a look at sections 4 and 8 of the  
implementation notes


 http://www.informatik.uni-freiburg.de/~thiemann/WASH/draft.pdf


I think there is also some work done about using Arrows for this  
problem, cf John Hughes' original paper. (I hear the use of Arrows was  
inessential, see the followup by Thiemann.)


IMH-and-probably-offtopic-O, the continuation-based approach is  
semantically nice but I don't think anyone has reconciled it with the  
general desire for clean and tidy URIs. Going to:


http://example.com/continuations/45345345

is not anywhere near as aesthetic / phishing proof / ... as going to  
e.g.


http://example.com/comments/edit/16

(Though I grant that hpaste URIs are tantalisingly mysterious.)

The general problem is providing a way for the programmer to  
(schematically) specify the URIs and handlers without getting bogged  
down in state machine encodings.


If someone's got some good ideas here, I'd love to hear about it (on  
the web-devel mailing list, perhaps).


cheers
peter

--
http://peteg.org/

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Ghc / cgi static linking

2008-06-01 Thread Peter Gammie

On 02/06/2008, at 5:26 AM, Don Stewart wrote:


pieter:
Yes, it is entirely possible to statically link entire CGI apps.


You might want to watch out for a bug in GHC 6.8.2 that means GHC's - 
static flag doesn't work. (At least for me, at least on Debian: the - 
lpthread flag is passed before the -lrt one, and symbols are left  
unresolved as a result.) Apparently the near-to-release 6.8.3 will fix  
this issue.


Presumably dons is using a more recent GHC than 6.8.2, or other (BSD?)  
platforms are not affected.


Note also you may have to tweak sundry .cabal files to add extra- 
libraries fields. As an example, I added this to HSQL's PostgreSQL  
backend to get it to statically link:


extra-libraries: pq, crypt, pthread

(If anyone cares you need to build PostgreSQL without kerberos as that  
doesn't seem to statically link any more.)


cheers
peter

--
http://peteg.org/

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: the Network.URI parser

2008-05-28 Thread Peter Gammie

On 28/05/2008, at 12:28 PM, Miguel Mitrofanov wrote:

I am taking comments on a web forum from arbitrary people. The  
interpretation of the HTML occurs at the user's browser. A lot of  
people will be using outdated browsers (IE 5.5 / 6), ergo security  
(at the source) becomes my problem. I cannot force them to upgrade  
their browsers.


I think this is very wrong for two reasons. First of all, the more  
web sites care of old browsers, the later people will upgrade them,  
therefore preventing the progress in Web (though IE 5.5 is not THAT  
old and bad, so this argument is not so strong). In Russia we some  
times say that a user with an outdated browser is an EPTH (Evil  
Pinocchio To Himself, don't ask me about source of this term).


I am not encouraging people to stick with IE 5.5, I am trying to  
prevent them from being exploited when visiting my site. It is a good- 
faith-best-effort, not something I will formally prove.


Secondly, I don't think that filtering HTML coming from an arbitrary  
user is a good idea. HTML is not very human-readable and too complex  
to achieve real safety without lots of work. My suggestion is to use  
some home-grown wiki-like syntax - it's easier to enter (*bold*  
instead of bbold/b), easier to read (and your users would  
sometimes read their comments before posting - to check  
correctness), and easier to process, since it can't have security  
holes you're not aware of.


Did you read my post? I validate the XHTML against a restricted  
variant of the XHTML 1.0 Strict DTD. I want to ensure that if it  
validates, it is safe, as I explained before. I think the style  
attribute is unsafe, so I can remove it from the DTD. (We can simulate  
the effect of style by providing pre-made CSS classes and vetting  
the class attribute.) I am sure you can generalise from here.


As for some other kind of markup: if my users were sophisticated  
enough to use something else, then I would use it. The target audience  
is not very literate, let alone computer literate.



But you're right, we are off topic.


Sorry to reply to your post then, I couldn't resist. :-/

cheers
peter
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: static linking

2008-05-28 Thread Peter Gammie

Hello,

Further on my static linking woes:

debian ~$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 6.8.2
-debian ~$ cat T.hs
main :: IO ()
main = putStrLn Hello world
-debian ~$ ghc -optl-static -static --make T.hs
Linking T ...
/usr/lib/gcc/i486-linux-gnu/4.2.3/../../../../lib/ 
librt.a(timer_create.o): In function `timer_create':

(.text+0x107): undefined reference to `pthread_once'
...
 references to missing pthread symbols 

Does anyone have static linking working for GHC 6.8.2 and can inform  
me of the magic incantation? Get the latest development version from  
darcs, perhaps?


BTW when I said move to the end, I meant move to the end of -l  
flags.


cheers
peter

On 27/05/2008, at 10:37 AM, Peter Gammie wrote:


Hello,

I am having a bit of trouble static linking my program using GHC  
6.8.2.


In brief: rt uses pthread, but -lrt is the final thing on the  
command line passed to the linker, and so the pthread symbols are  
not resolved. Manually moving -lpthread to the end of the collect2  
command line does the trick.


The question is how to do this using ghc.

This is on Debian, using the 6.8.2-5 from unstable.

I can provide the command lines if that is helpful.

Note the same setup worked fine under GHC 6.6.1.

cheers
peter


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: the Network.URI parser

2008-05-27 Thread Peter Gammie

On 27/05/2008, at 6:08 PM, Neil Mitchell wrote:


It most certainly is a security flaw.


In the src of an img, yes, probably. In the href of a link, its a
completely valid thing to do - and one that I've done loads of times.
The URI is fine, its just the particular location that is dodgy.


Sure, but for other reasons (potential inaccessibility) I am quite  
happy to ban JavaScript from URIs. (Not all URIs, just the ones coming  
from untrusted users.)


whole pile of dodgy URIs. Most get culled (in my case) by the HaXml  
parser
and/or XHTML 1.0 Strict validation, and now I hope to eliminate the  
rest by

carefully handling the URIs.


I don't think that's possible. A URI can validly have javascript, and
can validly be a lot of things which are unsafe.


Sure, I now realise my notion of allowable URI goes beyond (is an  
additional restriction of) the RFC.


One way to show the URI is valid is to fetch what it is pointing to,  
and ensure it is an image or whatever.


On that topic, does anyone have any good advice for handling these  
things?


My advice is that you are targeting security at the wrong level. You
shouldn't be cleaning the HTML to get a secure page, you should be
having the level that interprets the HTML be secure regardless of the
input.


I am taking comments on a web forum from arbitrary people. The  
interpretation of the HTML occurs at the user's browser. A lot of  
people will be using outdated browsers (IE 5.5 / 6), ergo security (at  
the source) becomes my problem. I cannot force them to upgrade their  
browsers.


If anyone knows of the state-of-the-art in this area, I'd  
appreciate a

pointer.

http://htmlpurifier.org/live/smoketests/printDefinition.php

doesn't seem to think the style attribute is unsafe. Have they not  
been

following the MySpace fiascos?


Safety is a property of the HTML viewer, not of the HTML or CSS.


Well, yes and no. I am heavily restricting the XHTML I accept (e.g. no  
scripts, no style attribute, ...), in an attempt to keep things  
visually accessible and avoid phishing attacks. I was alluding to the  
use of absolute positioning in CSS. If I had a CSS parser I might  
allow the style attribute.


Safety for me involves making sure that what is displayed is  
trustworthy and easily identifiable as such. This is not something the  
HTML viewer can always help with.


I think we're off-topic enough for me to stop here. Thanks for your  
comments.


cheers
peter
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] library for drawing charts

2008-05-24 Thread Peter Gammie

Hello,

Has anyone got some code for drawing charts?

I don't mean graphs of functions, ala

http://dockerz.net/twd/HaskellCharts

and I don't mean calls to the Google Charts API ala

http://community.livejournal.com/evan_tech/241080.html

I would like something that can generate PNGs in memory, i.e. not  
directly to a file.


This is close to what I have in mind:

http://www.fred.net/brv/chart/

I'd like 2D pie charts, bar charts and something like a google-o-meter.

Any pointers?

cheers
peter
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: HaXml and the XHTML 1.0 Strict DTD

2008-05-21 Thread Peter Gammie

On 30/04/2008, at 5:32 PM, Malcolm Wallace wrote:


Peter Gammie [EMAIL PROTECTED] wrote:


The most-recent darcs version relies on a newer ByteString than I
have, so it is not easy for me to test it.


I believe there was a patch to fix this.  Apparently only one  
version of
the bytestring package (0.9.0.1) ever exported the 'join' function,  
and
a different version with the same number (but not exporting 'join')  
was

uploaded to Hackage!  'Join' has since been replaced by 'intercalate',
which is available in all versions 0.9.x.


Thanks. I don't doubt it works with a newer bytestring, I just can't  
readily use such a thing.



A recent (this year) darcs version failed to parse the DTD, yielding
this error:


I didn't try the full XHTML DTD, but the fragment you included in your
message was parsed just fine by the darcs version of HaXml/ 
DtdToHaskell.


Can you please try the full XHTML 1.0 Strict DTD? At the same time,  
can you verify that it handles this part of it properly (circa line  
854):


!ELEMENT table
 (caption?, (col*|colgroup*), thead?, tfoot?, (tbody+|tr+))

Using a slightly hacked HaXml v1.13.3, I get this from DtdToHaskell:

data Table = Table Table_Attrs (Maybe Caption)
   (OneOf2 [Col] [Colgroup]) (Maybe Thead) (Maybe  
Tfoot)

   (OneOf2 (List1 Tbody) (List1 Tr))
   deriving (Eq,Show)

My expectation is that we can have a table without a col or  
colgroup child. The W3 validator seems to agree with that  
interpretation. When I use the HaXml validator with this DTD I get  
this (e.g.):


Element table should contain (caption?,(col*| 
colgroup*),thead?,tfoot?,(tbody+|tr+)) but does not.


Element table should contain (col*|colgroup*) but does not.

cheers
peter
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: HaXml and the XHTML 1.0 Strict DTD

2008-05-21 Thread Peter Gammie

On 21/05/2008, at 5:44 PM, Malcolm Wallace wrote:


Peter Gammie [EMAIL PROTECTED] wrote:


!ELEMENT table
 (caption?, (col*|colgroup*), thead?, tfoot?, (tbody+|tr+))

Using a slightly hacked HaXml v1.13.3, I get this from DtdToHaskell:

data Table = Table Table_Attrs (Maybe Caption)
   (OneOf2 [Col] [Colgroup]) (Maybe Thead) (Maybe  
Tfoot)

   (OneOf2 (List1 Tbody) (List1 Tr))
   deriving (Eq,Show)


This looks entirely correct to me.


I realised that as soon as I sent it. :-)


My expectation is that we can have a table without a col or
colgroup child.


Ah, yes I can see why that is permitted, but I guess HaXml's validator
is not yet smart enough to be able to choose whether it has seen an
empty list of col or an empty list of colgroup.  :-)

Here is a suggested fix.  Let me know if it works for you.  In
src/Text/XML/HaXml/Validate.hs, around line 220, use the following  
diff

over the local defn of 'choice':

   choice elem ns cps =  -- return only those parses that don't give  
any errors
   [ rem | ([],rem) - map (\cp- checkCP elem (definite cp) ns)  
cps ]

+   ++ [ ns | all possEmpty cps ]
   where definite (TagName n Query)  = TagName n None
 definite (Choice cps Query) = Choice cps None
 definite (Seq cps Query)= Seq cps None
 definite (TagName n Star)   = TagName n Plus
 definite (Choice cps Star)  = Choice cps Plus
 definite (Seq cps Star) = Seq cps Plus
 definite x  = x
+ possEmpty (TagName _ mod)   = mod `elem` [Query,Star]
+ possEmpty (Choice cps None) = all possEmpty cps
+ possEmpty (Choice _ mod)= mod `elem` [Query,Star]
+ possEmpty (Seq cps None)= all possEmpty cps
+ possEmpty (Seq _ mod)   = mod `elem` [Query,Star]


Fantastic, thanks, that seems to work fine. A couple of nits: your use  
of `elem` refers to Prelude.elem, so I added the Prelude as a  
qualified import as P and changed those shadowed references to `P.elem`.


I will try to send you a patch against 1.13.3 with all these little  
bits and pieces, when my project is finished.


Can you lay out some kind of plan for HaXml? (is 1.13.x now dead, is  
1.19.x stable, ...?) This would help for new-ish projects like mine.



Are there other places, apart from the validator, where a similar
problem arises?


I do not know, I am merely using the DTD and HTML parsers, the CFilter  
combinators, the pretty printer and the validator. They all seem fine  
on a cursory check.


(In general HaXml has been working quite well. Thanks for producing  
such a long-lived and well-thought-out library.)


cheers
peter

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] another Newbie performance question

2008-05-18 Thread Peter Gammie
You want to lazily read a CSV file? I had a crack at writing a module  
for that:


http://peteg.org/blog/AYAD/Project/2008-04-11-LazyCSVParser.autumn

It is not quite RFC compliant (I believe that is clearly commented  
upon).


As I say there, anything based on (older versions of) Parsec is likely  
to be too strict in the general case.


cheers
peter
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] FFI Query: How to free a CString allocated in Haskell

2008-04-29 Thread Peter Gammie

On 29/04/2008, at 12:58 PM, Brandon S. Allbery KF8NH wrote:


On Apr 29, 2008, at 1:45 , Verma Anurag-VNF673 wrote:
A naïve question I have now after reading your mail. How do I call  
MarshallAlloc.free from my C code because that's where I need to  
free it?


Provide a Haskell wrapper function to deallocate / free it, as a  
parallel to the function that allocates and returns it to the C code.


I would also point out the existence of withCString and friends. Tread  
carefully if you care about Unicode!


cheers
peter

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] HaXml and the XHTML 1.0 Strict DTD

2008-04-28 Thread Peter Gammie

Is anyone using HaXml to validate XHTML Strict?

The old 1.13.2 version has some bugs in how it handles attributes that  
stop me from using it. It handled the DTD parsing fine.


The most-recent darcs version relies on a newer ByteString than I  
have, so it is not easy for me to test it.


A recent (this year) darcs version failed to parse the DTD, yielding  
this error:


validate: In a sequence:
  in content spec of ELEMENT decl: head
  When looking for a non-empty sequence with separators:
In a sequence:
Expected % but found |
  in file xhtml1  at line 252 col 50
when looking for a content particle

  when looking for a content particle

This is the context:

!-- Document Head  
===--


!ENTITY % head.misc (script|style|meta|link|object)*

!-- content model is %head.misc; combined with a single
 title and an optional base element in any order --

!ELEMENT head (%head.misc;,
 ((title, %head.misc;, (base, %head.misc;)?) |
  (base, %head.misc;, (title, %head.misc;

I appreciate any advice on this.

cheers
peter
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] FFI Query: How to free a CString allocated in Haskell

2008-04-28 Thread Peter Gammie

On 28/04/2008, at 7:23 PM, Bulat Ziganshin wrote:


Hello Verma,

Monday, April 28, 2008, 4:11:51 PM, you wrote:


 newCString str



Now once I call this function from C code, I am freeing the allocated
memory using free function. I want to confirm that this is the right
thing to do.


yes, i've traced this function down to mallocArray - mallocBytes -
malloc() calls


Depending on how you feel about it, Bulat's response either entirely  
answers your question or is neither here nor there.


If you want to write portable code, you should check with the FFI  
spec. If you just want to write code that works with GHC as it  
presently is, you can strace it or whatever.


As Bulat has already given you the pragmatic answer, allow me to grind  
my axe a little. In the FFI spec on p33, we find:



newCString :: String - IO CString
newCStringLen :: String - IO CStringLen

Allocate a memory area for a Haskell string and marshal the string  
into its C representation.
There are two variants of the routine, one for each supported string  
representation. The
memory area allocated by these routines may be deallocated using  
MarshalAlloc.free.


OK, so back on p19 we find:


free :: Ptr a - IO ()

Free a block of memory that was allocated with malloc, mallocBytes,  
realloc, reallocBytes,
or any of the allocation functions from MarshalArray (see Section  
5.9).


and we can draw the inference (reading between the lines) that this  
function need not have a relation to C's malloc. (Roughly, the  
intention is to allow a Haskell implementation to use whatever memory  
management it likes.)


So no, using C's free is not the right thing to do. It will probably  
work in the real world, but you should try to use Haskell's free if  
possible.


cheers
peter
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: HDBC, character encoding

2008-04-04 Thread Peter Gammie

On 03/04/2008, at 9:10 PM, John Goerzen wrote:


On 2008-04-01, Peter Gammie [EMAIL PROTECTED] wrote:

I added some stuff to HSQL (not HDBC) and HaskellDB so that UTF8 can
be used to talk to the database. It's not very pretty though, so I
haven't tried to get it merged.


Do you have a diff somewhere?  I'd be interested in your approach, to
see if the same thing would make sense in HDBC.


My approach is simple: when creating a connection to the database, ask  
for two functions (a codec pair) and stash them with the rest of the  
DB state. The types involved are [Word8] and String. I started out  
trying to use ByteString instead of [Word8] but it didn't bring much  
to the table in my case.



I had generally been of the opinion that HDBC should just pass data
through, however it is obtained, and let the programmer set the
encoding as desired.  If this approach isn't working for people, I'd
like to fix it, but want to make sure it's done right.


Assuming you're talking about the FFI's mandated behaviour, I'm not  
very comfortable with the encoding depending on the C locale, for two  
main reasons:


- the program I'm hacking runs on some web host's server that is an  
unknown quantity.
- GHC has a few quirks in how it implements the FFI, better to avoid  
the part that interprets characters.


If you want to be general, I guess you could abandon String (at the  
HDBC level) and use [Word8]/ByteString everywhere, then provide some  
convenience wrappers. Then you can uniformly handle binary and textual  
data. I am not familiar with your project though.


cheers
peter
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: HDBC, character encoding

2008-04-04 Thread Peter Gammie

On 04/04/2008, at 9:27 PM, John Goerzen wrote:


I can see this being a performance and ease-of-use win in some
situations.  I don't think it's an actual feature difference, though.
If you can represent it as a [Word8], you can represent it as a
[Char], and it will be converted to the same underlying data for the
trip through FFI.


Sure. I prefer to keep things separate: Char is for Unicode  
characters, [Word8]/ByteString is for concrete representations. It's  
more about type safety than efficiency.


cheers
peter
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] HDBC, character encoding

2008-03-31 Thread Peter Gammie

On 31/03/2008, at 11:42 PM, Bjorn Bringert wrote:


2008/3/26 Adrian Neumann [EMAIL PROTECTED]:

Hi,

I wrote a CGI program to access a Postgres database using HDBC. [...]


I think that Peter Gammie (copied) has some code to deal with this.


I added some stuff to HSQL (not HDBC) and HaskellDB so that UTF8 can  
be used to talk to the database. It's not very pretty though, so I  
haven't tried to get it merged.


cheers
peter
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] modeling ANSI C structs in Haskell?

2008-02-04 Thread Peter Gammie

Vasili,

On 04/02/2008, at 10:04 PM, Galchin Vasili wrote:

  I am reading through the FFI doc. Any suggestions on enabling  
Haskell programmers to model ANSI C structs that will be passed down  
to C run-time?


The FFI spec is a wonderful document, but is of limited use in  
learning to use the FFI for practical tasks. I suggest you look into  
c2hs or some other tool that tries to help you with marshalling data  
structures (as compared to providing mechanisms sufficient for doing  
marshalling).


I suggest you do this even if you don't end up using a tool, as the  
generated Haskell has some carefully designed idioms that will  
definitely help.


cheers
peter
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Wikipedia on first-class object

2007-12-28 Thread Peter Gammie

On 28/12/2007, at 4:21 PM, Miguel Mitrofanov wrote:


How can I test that partial order in Haskell ?


You can't. It's kinda internal. More specifically, if you try to  
compute a value, which is not maximal in this order, you'll get an  
error or loop forever. But you still can use such values in your  
programs if you don't try to compute them. The point is, maximal  
values are the only interesting ones, and all others are just  
approximations.


Right, so when I say to GHCi:

Prelude take 5 [1..]

and it says:

[1,2,3,4,5]

then it really has computed the entirety of the infinite sequence  
[1..], and not some approximation?


Perhaps it is better to say that in a lazy language both  
approximations and maximal values (least upper bounds of a chain) are  
interesting. In a strict language we only get our hands on the latter.  
The take lemma nicely captures this kind of thinking. (Ask google  
about the generalised take lemma, it's a nice paper.)


Also note that the notion of equality that's being thrown around is  
observational equality, i.e. x=y implies that for all contexts  
(some expression with a suitably-typed hole), if you plug 'x' into the  
hole, and 'y' into hole, then those two expressions denote the same  
value. ((Roughly) equivalently, you can use the idea of Leibniz  
equality: there is no function that distinguishes them. These notions  
may diverge in Haskell - does anyone know?) As Lennart observed, any  
(semi-)computable equality predicate is not going to be that strong.


cheers
peter
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Wikipedia on first-class object

2007-12-28 Thread Peter Gammie

On 28/12/2007, at 5:50 PM, Miguel Mitrofanov wrote:


Right, so when I say to GHCi:



Prelude take 5 [1..]



and it says:



[1,2,3,4,5]



then it really has computed the entirety of the infinite sequence



[1..], and not some approximation?



Of course not! In fact, it doesn't even compute the value 1. It  
just juggles with the bytes somehow, so that it seems that it  
computes the whole sequence and then applies take 5. But does it  
really matter if it computes 5 integers, or 10, or the whole  
sequence, at least if we are not concerned about performance?


I'll bite. So what do you expect:

take 5 [1,2,3,4,5,undefined]

to do? How about:

take 5 (1:2:3:4:undefined)

?

So it does seem to matter how much of the list it evaluates...


Perhaps it is better to say that in a lazy language both
approximations and maximal values (least upper bounds of a chain) are
interesting.


Well, that depends of your notion of interesting.


I defined it - I'm interested in things that are observationally  
equivalent. Please read the generalised-take-lemma paper. It will  
clear up some of this confusion.


cheers
peter

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Wikipedia on first-class object

2007-12-28 Thread Peter Gammie

On 28/12/2007, at 7:19 PM, Miguel Mitrofanov wrote:


So what do you expect:



take 5 [1,2,3,4,5,undefined]



to do?


Nothing! It's a value, not an instruction!


Dang, I knew I'd choose at least one wrong word in all of that. :-P

What is it's value, then? ... and what is the value of the other  
example I gave?


(What would GHCi print? What is another, perhaps even simpler,  
expression it is equal to? ... a substantive answer please! Then  
please square that with your comment that we don't care how much of  
the list gets evaluated.)


(Jules, thanks for your response. My questions are Socratic, not  
rhetorical. I'm benefiting by having to choose my words very, very  
carefully. :-)


cheers
peter
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Sending email from a Haskell program

2007-09-26 Thread Peter Gammie

Hello,

Does anyone have a library for sending email from a Haskell program?  
I'd like something portable and cabalised.


I note there is code in darcs to send email on Windows and UNIX-y  
systems, and also something in WASH (I know not what). Apparently  
there is an SMTP server of some kind (?) in HAppS, but I want to re- 
use the system's MTA.


BTW is anyone else looking at the darcs codebase and thinking that  
there are many useful libraries lurking there?


cheers
peter
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Does laziness make big difference?

2007-02-15 Thread Peter Gammie

Nick,

Roughly, I'd say you can fudge laziness in data structures in a  
strict language without too much bother. (I don't have much  
experience with this, but the existence of a streams library for  
OCaml is the sort of thing I mean. There are plenty of papers on co- 
iterative streams and suchlike that show the general pattern.)


If you wish to add control structures you would need to use the lazy  
keyword a lot, e.g.:


if cond then *lazy* S1 else *lazy* S2

and for more complicated structures it's not going to be always clear  
what needs to be suspended. Laziness is a conservative default here.  
(If you want to write an EDSL in a non-lazy language, you'll need to  
use some kind of preprocessor / macros / ... - in other words, a two- 
level language - or do thunking by hand, as above, or live with doing  
too much evaluation.)


One way to gauge how useful laziness really is might be to look  
through big ML projects and see how often they introduce thunks  
manually. A thunk there is usually something like fn () = ...  
IIRC. Also IIRC, Concurrent ML is full of them.


Dare I say the tradeoff is between a relatively simple operational  
model (so you can judge space and time usage easily) and semantic  
simplicity (e.g. the beta rule is unrestricted, easing program  
transformation).


cheers
peter
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe