Re: [Haskell-cafe] mathematical notation and functional programming

2005-01-28 Thread Jorge Adriano Aires
Things I'm unhappy about are for instance f(x) \in L(\R) where f \in L(\R) is meant F(x) = \int f(x) \dif x where x shouldn't be visible outside the integral O(n) which should be O(\n - n) (a remark by Simon Thompson in The Craft of Functional

Re: [Haskell-cafe] Converting from Int to Double

2005-01-26 Thread Jorge Adriano Aires
How can I convert an Int into a Double? You don't convert to, you convert from :-) The function 'fromIntegral' is probably what you want. And what function can I use to convert from Double to Int (the inverse of fromIntegral) ? Use the functions in the RealFrac class.

Re: [Haskell-cafe] Re: what is inverse of mzero and return?

2005-01-25 Thread Jorge Adriano Aires
On Tuesday 25 January 2005 02:25, Jan-Willem Maessen wrote: On Jan 24, 2005, at 8:53 PM, Jorge Adriano Aires wrote: And it would say nothing about things like: return 4 return 5 ==?== return 5 I can live with it. I feel obliged to point out (because the repeated references

Re: [Haskell-cafe] using Map rather than FiniteMap

2005-01-25 Thread Jorge Adriano Aires
Just did a search after my last post and learned that FiniteMap is bad. Discoverd that Data.Map is the intended replacement. Downloaded it and modified it to work with 6.2. Blazingly fast! Yay. Hi, just curious, How much trouble was getting it to work with ghc 6.2 and adapting your

Re: [Haskell-cafe] Re: what is inverse of mzero and return?

2005-01-24 Thread Jorge Adriano Aires
Right, but we are dealing with the type system here. Remember Haskell monoids are functors on types, not on values ... (ie the base objects the 'category theory' is applied to are the types not the values)... Therefore we only consider the types when considering Monads. How so? Functors map

Re: [Haskell-cafe] Re: what is inverse of mzero and return?

2005-01-24 Thread Jorge Adriano Aires
We face a severe problem here, not only that IO a is not an instance of Eq, which takes this whole discussion outside the realm of Haskell, on top of that we find the horrible fact that x /= x may be true in the IO Monad, consider x = getLine = putStrLn or anything similar -- actually

Re: [Haskell-cafe] Re: what is inverse of mzero and return?

2005-01-24 Thread Jorge Adriano Aires
A constant c :: a is just morphism(function) c : 0 - a, where 0 is the initial object (empty set). --- Rant2 correction Opss I messed up here. Should be terminal should 1- a (terminal object/unit set). At least that's how I usually think of constants in haskell 1 is ()... so I think I

Re: [Haskell-cafe] Re: what is inverse of mzero and return?

2005-01-24 Thread Jorge Adriano Aires
This isn't obvious to me. So x is an action, and it does not always produces the same side effects when executed. But why should that make x/=x? It is the same action, it gets one line from the input, and then prints it... OK, but then the different side-effects could not be used to

Re: [Haskell-cafe] Re: what is inverse of mzero and return?

2005-01-24 Thread Jorge Adriano Aires
(Sorry about the recurrent self answers) Maybe (not sure) it is sensible to sapecify return::(a - IO a), as an action with no side effects such that return x === return x iff x === x. return x === return y iff x === y-- this is what I meant to write. But even that is not enough,

Re: [Haskell-cafe] Re: what is inverse of mzero and return?

2005-01-23 Thread Jorge Adriano Aires
What would happen if this was the definition? instance MonadPlus [] where mzero = [] mplus a b | a == [] = b | otherwise = a Isn't the above a monoid as well? Yes. Is there only on correct definition of a monad/monoid on lists - or does anything that satisfies

Re: [Haskell-cafe] Re: what is inverse of mzero and return?

2005-01-23 Thread Jorge Adriano Aires
One common example is using MonadPlus for some backtracking algorithm, then instantiatiating it to Maybe or List instance depending on wether you just want one solution or all of them. Backtracking only works with the first kind, even if you're only interested in the first solution. This

Re: [Haskell-cafe] Re: what is inverse of mzero and return?

2005-01-23 Thread Jorge Adriano Aires
I think it would be helpful if all these classes came with their laws prominently attached in their Haddock documentation or wherever. Agree. The trouble with MonadPlus is that the precise set of associated laws is either unspecified or not the most useful (I assume there's a paper on the

Re: [Haskell-cafe] Re: what is inverse of mzero and return?

2005-01-23 Thread Jorge Adriano Aires
Am Sonntag, 23. Januar 2005 15:58 schrieb Jorge Adriano Aires: I'm not arguing that definition would be wrong. It is a monoid. This is the instance for (): instance MonadPlus() where mzero = () mplus a b = () Maybe I'm stupid, but: class Monad m = MonadPlus m where mzero

Re: [Haskell-cafe] Re: what is inverse of mzero and return?

2005-01-22 Thread Jorge Adriano Aires
But only some instances (such as []) satisfy this: (mplus a b) = c = mplus (a = c) (b = c) Other instances (IO, Maybe) satisfy this: mplus (return a) b = return a I think mplus should be separated into two functions. How would we implement the first kind in the Maybe instance of

Re: [Haskell-cafe] Re: what is inverse of mzero and return?

2005-01-22 Thread Jorge Adriano Aires
snip Only the monoid Maybe a is not very nice (nor is the monoid IO a),since the second argument of the composition is in general ignored. snip So I think, rather than separating mplus, one should think about whether it is sensible to make Maybe and IO instances of MonadPlus in the first

Re: [Haskell-cafe] Top Level etc.

2005-01-19 Thread Jorge Adriano Aires
Perhaps one could have top-level implicit parameters (or top-level contexts in general): module (?myvar :: IORef Int) = Random where Hi! I suggested something very similar to this some months ago, syntax and all. Nice to see I'm not the only one thinking along this lines.

Re: [Haskell-cafe] Some random newbie questions

2005-01-09 Thread Jorge Adriano Aires
On Friday 07 January 2005 12:03, Ketil Malde wrote: Naive use of foldl.  I tend to think the default foldl should be strict (ie. replaced by foldl') -- are there important cases where it needs to be lazy? Hi, One simple example would be, reverse = foldl (flip (:)) [] J.A.

Re: [Haskell-cafe] Some random newbie questions

2005-01-09 Thread Jorge Adriano Aires
On Friday 07 January 2005 12:03, Ketil Malde wrote: Naive use of foldl.  I tend to think the default foldl should be strict (ie. replaced by foldl') -- are there important cases where it needs to be lazy? Hi, One simple example would be, reverse = foldl (flip (:)) [] A better example

Re: [Haskell-cafe] Some random newbie questions

2005-01-09 Thread Jorge Adriano Aires
No, it would work with strict foldl too. In fact in the absence of optimization it would work better (uses less time and space). The optimization required is inlining and strictness analysis. Is this also true if your just going to use the first few elements after reversing it? A function

Re: [Haskell-cafe] Some random newbie questions

2005-01-09 Thread Jorge Adriano Aires
On Sunday 09 January 2005 21:30, Marcin 'Qrczak' Kowalczyk wrote: Jorge Adriano Aires [EMAIL PROTECTED] writes: No, it would work with strict foldl too. In fact in the absence of optimization it would work better (uses less time and space). The optimization required is inlining

Re: [Haskell-cafe] Some random newbie questions

2005-01-09 Thread Jorge Adriano Aires
(+) is usually strict on both arguments (although in principle it does not have to be true because of overloading, which implies that a compiler can only optimize particular specializations of sum, not generic sum). Since you mention it, there was some talk about this in the #haskell channel,

Re: [Haskell-cafe] Class Synonyms - example 2

2004-12-11 Thread Jorge Adriano Aires
Jorge, Besides the case where 'a' is the same as 'b', there is also another interesting case. That is when you have both, Foo A B and Foo B A. This is a known property (named DoubleFoo) [...] Again, with -fallow-undecidable-instances: \begin{code} class (Foo a b, Foo b a) =

[Haskell-cafe] Class Synonyms

2004-12-10 Thread Jorge Adriano Aires
Hello! I got a multi-parameter type class: class Foo a b | a - b where foo_method1 :: ... foo_method2 :: ... ... And some particular cases are important on their own, like the one where 'a' and 'b' are the same, I call elements with this property, Bar. So I defined: class Foo a

[Haskell-cafe] Class Synonyms - example 2

2004-12-10 Thread Jorge Adriano Aires
Maybe I should have included a more interesting example in the previous mail. So I had this class: class Foo a b | a - b where foo_method1 :: ... foo_method2 :: ... ... Besides the case where 'a' is the same as 'b', there is also another interesting case. That is when you have

Re: [Haskell-cafe] foldlWhile

2004-11-20 Thread Jorge Adriano Aires
(opss just noticed I did a reply-to) The following is closer to the original, but doesn't work when the whole list is folded (i.e., p always satisfied): foldlWhile f p a = head . dropWhile p . scanl f a Serge's version returns the last 'a' that satisfies 'p', while yours Not really.

Re: [Haskell-cafe] FiniteMap-like module for unordered keys?

2004-11-09 Thread Jorge Adriano Aires
Hello, A hash-table becomes rather useless without mutable state AFAICS. Without it, one might almost just as well use a list of pairs... Could you please elaborate? Is there motive why an Hash Table, implemented as FiniteMap of Lists, for instance, wouldn't be worth to using over a simple

Re: [Haskell-cafe] QuickCheck - Extracting data values from tests

2004-09-04 Thread Jorge Adriano Aires
The generate function is exported: generate :: Int - StdGen - Gen a - a Thanks, that's the one I was missing. J.A. ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] QuickCheck - Extracting data values from tests

2004-09-02 Thread Jorge Adriano Aires
Hello all, When using Quickcheck, is there some way to extract generated data values to the IO Monad? I know I can collect and print information about test cases, but that's not enough. Data may be pretty complex, and there may be no parsers for it. If a test suddenly goes wrong,

[Haskell-cafe] QuickCheck - Extracting data values from tests

2004-09-01 Thread Jorge Adriano Aires
Hello all, When using Quickcheck, is there some way to extract generated data values to the IO Monad? I know I can collect and print information about test cases, but that's not enough. Data may be pretty complex, and there may be no parsers for it. If a test suddenly goes wrong, just having

Re: [Haskell-cafe] Monadic Composition

2004-05-12 Thread Jorge Adriano Aires
So, yes, it is useful, but should it be included in a standard Monad module? After all, this module contains mostly trivial functions ;) BTW. You can write this function using foldM: compM l a = foldM (#) a l where # is an often used reverse application operator: x # f = f x

[Haskell-cafe] Monadic Composition

2004-05-11 Thread Jorge Adriano Aires
Hello, I needed to compose monadic functions, since I couldn't find anything in Control.Monad so I defined my own. I first came up with a left associative version: compLM [f1,..., fn] a = (f1 a = f2) = ... = fn compLM:: Monad m = [a-m a] - (a-m a) compLM mfs a = foldl (=) (return a)

Pattern matching, implict par. question

2003-02-13 Thread Jorge Adriano
Hello, When trying type CTPar = ([Double],Int,Int) ctPar ::(?ctPar::CTPar)=CTPar ctPar@(us,n,j) = ?ctPar I got this error message in ghci is: Illegal overloaded type signature(s) in a binding group for ctPar, us, n, j that falls under the monomorphism restriction

Very simple question

2003-02-11 Thread Jorge Adriano
On style, yes. A concrete example of what I asked before. The following doesn't type check for obvious reasons. In your opinion what is the most elegant way to fix it? Like I said, I'm starting to feel like defining my own operators is the way to go. On the other hand, this kind of situation

Ints as ints and floats - Question on style

2003-02-08 Thread Jorge Adriano
Hello, Lately I've been coding functions where I have to use Int elements, both as Ints (e.g. as an array or list index) and Doubles/Floats (e.g. when performing arithmetic operations with Doubles/Floats). How do you usually deal with this? Some options I can think of are, 1. using

Re: Global variables?

2003-01-31 Thread Jorge Adriano
Hello, Is it even possible to make a global variable in Haskell? If yes, how? Thanks. (short answer, no time now...) Look here: http://www.haskell.org/pipermail/haskell-cafe/2002-January/002589.html Hope it helps ;) J.A. ___ Haskell-Cafe mailing

Re: Why no findM ? simple Cat revisited

2002-11-20 Thread Jorge Adriano
Simple Cat (revisitied) \begin{code} import IO findM f [] = return Nothing findM f (x:xs) = do { v - x; if f v then return (Just v) else findM f xs } isLeft (Left _) = True isLeft _ = False main = findM (isLeft) (hCat stdin) where hCat h = try (hGetLine h) : hCat h \end{code}

library of monadic functions [was: Why no findM ? simple Cat revisited]

2002-11-20 Thread Jorge Adriano
I appreciate your comment. I agree that the type of findM should be the one you suggested, and it still fits my original purpose. It's no more than a step arout. \begin{code} import IO findM f [] = return Nothing findM f (x:xs) = do { b - f x; if b then return (Just x) else findM f xs }

Re: Bug? [was: Implicit params]

2002-11-18 Thread Jorge Adriano
Now fixed in the HEAD, and will be in 5.04.2 Thanks for pointing it out. Simon Thanks :) J.A. ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe

Bug? [was: Implicit params]

2002-11-14 Thread Jorge Adriano
On Thursday 14 November 2002 18:47, Iavor S. Diatchki wrote: hello, Well, actually you must be right since the pure field defines a pure (projection) function... Hmmm, ok, can someone explain this to me, data E s = E{ refi :: STRef s Int, refc :: STRef s Char, m

Re: Record of STRefs better than STRef to a Record?

2002-11-13 Thread Jorge Adriano
If I use an STRef to a record, will a new record be created each time I want to update a single field? Or can I expect GHC to optimize it and have the field of the record updated in place? You'll get a new record for each update. This might not be so bad though, depending on the

Re: producing and consuming lists

2002-11-06 Thread Jorge Adriano
But like I just showed, sometimes paring them may not be a natural approach though... Yeah, I understand what you mean. In the examples you give, you could always try to make the appended stuff (the zs, etc) the same length by appending Nothings, but probalby not a general solution. Yes

Re: Dealing with configuration data

2002-09-25 Thread Jorge Adriano
Evening, I'm trying to write a utility that reads in some user preferences from a pre-determined file, does some work, and exits. Sounds simple enough. The problem I'm having is with the preferences: How do I make it available throughout the entire program? (FWIW, most of the work is

Re: mutable records

2002-09-10 Thread Jorge Adriano
Hi, thx for this reply. Is there any overhead using this mutable? I just thought I should point out that Mutable is not an haskell type. You can see in the Utils module that it is just a type synonim for IORef: http://icfpcontest.cse.ogi.edu/simulator/pfe.cgi?Utils#Mutable

Re: A problem with haskell-mode

2002-09-06 Thread Jorge Adriano
Hi, all, I installed the latest version of Haskell mode for emacs. Whenever I load haskell major mode by opening a haskell file, Xemacs gives me the following error message: (1) (error/warning) Error in `post-command-hook' (setting hook to nil): (void-variable imenu--index-alist) My

Re: Read File

2002-05-01 Thread Jorge Adriano
- [moving to haskell-cafe] I want to read some data from a text file. I accomplished it but I want to read data from file as a Integer list for example text file has [1,2,3,5] - Wait you actually have [1,2,3,5] - and when I read this data

Re: I need some help

2002-03-26 Thread Jorge Adriano
However the user of the program give some argument then program is starting. And I want to use this arguments for example at the end of the program. What will I do. Good question. I've had a bad time with this, some in this list proably got tired of me saying the same thing over and

literate haskell (again)

2002-03-22 Thread Jorge Adriano
Tried using Andrew Cookes haskell.sty and liked it a lot, but seems like the (X)emacs haskell mode doesn't support the \begin{code} \end{code} literate programming style, just the one where code is preceded by ' '. Anyone has got an hack available for this? J.A.

Re: literate haskell (again)

2002-03-22 Thread Jorge Adriano
On Friday 22 March 2002 16:31, you wrote: Jorge Adriano [EMAIL PROTECTED] writes: Tried using Andrew Cookes haskell.sty and liked it a lot, but seems like the (X)emacs haskell mode doesn't support the \begin{code} \end{code} literate programming style, just the one where code is preceded

literal haskell mode (nice :)

2002-03-22 Thread Jorge Adriano
of 'psgml-mode' is highly recommended. It is, of course, a ;; part of Debian GNU/Linux. ;; Modified by Marco Pantaleoni [EMAIL PROTECTED] ;; to allow execution of an hook on mode switching. ;; Also added a standard mode hook and some documentation strings. ;; Modified by Jorge Adriano [EMAIL

Re: literal haskell mode (nice :)

2002-03-22 Thread Jorge Adriano
On Friday 22 March 2002 23:27, Jorge Adriano wrote: I got some tips from some people at #xemacs in openprojects.org and cam up with the file in attachment. I know nothing about e-lisp so beware!! Opss I forgot: The original file is Copyrighted by David Welton and it is located here: http

Re: literal haskell mode (nice :)

2002-03-22 Thread Jorge Adriano
I got some tips from some people at #xemacs in openprojects.org and cam up with the file in attachment. I know nothing about e-lisp so beware!! Last e-mail today. Forgot to actually tell what was this for (need ti get some sleep :)... It's easy to guess by looking at the file anyway the idea

Re: literate haskell

2002-03-21 Thread Jorge Adriano
Thanks for all your answers :-) J.A. ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe

literate haskell

2002-03-20 Thread Jorge Adriano
Why is it necessary to leave a blank line between comments and code? I'm using LaTeX in my lhs files, with the code inside a verbatim environment, and I'd rather start writing my code right after the \begin{verbatim}. I'd also like to know if anyone as changed is xemacs configuration file in

Re: efficiency question

2002-02-09 Thread Jorge Adriano
On Saturday 09 February 2002 11:38, Jorge Adriano wrote: If you make it strict on the (,), like:  test3 l =      let s = foldr (\x (a,b) - ((,)$!x+a)$!x-b) (1,1) l      in  s Things will get worst. Well, that's what I expected, the elements of the list will b reduced to head normal form

Re: character syntax

2002-02-08 Thread Jorge Adriano
On Friday 08 February 2002 14:35, Ketil Z. Malde wrote: Jorge Adriano [EMAIL PROTECTED] writes: Haskell looks nice... Isabell looks beautiful :-) I'm not familiar with Isabell, but aren't we comparing apples and oranges here? E.g. you can prettify .lhs pretty nicely with one of the LaTeX

Re: efficiency question

2002-02-08 Thread Jorge Adriano
I'd say that's because in the second case you also got to apply the (,), besides the (+)/(-) constructor during the transversing... Am I right? opss... I meant to write: the (,) constructor besides the (+)/(-)... J.A. ___ Haskell-Cafe mailing list

Re: Random questions after a long haskell coding day

2002-01-27 Thread Jorge Adriano
On Sunday 27 January 2002 05:36, Hal Daume III wrote: For your last question (about reduction to hnf), use the attached code; search the haskell mailing list for deepseq for more. Thanks... I found myself trying to define a function deepSeq :: [a]-[a] to evaluate all the elements of the

Random questions after a long haskell coding day

2002-01-26 Thread Jorge Adriano
Am I the only one who'd like to have some the function specified by scan_and_fold f e xs= (scanl f e xs, foldl f e xs) In the Lists library. Or is it there somewhere and I missed it? What about: pair (f,g) x = (f x, g x) cross (f, g) = pair(f.fst, g.snd) I kind of like point free style.

Re: performance of monads

2002-01-24 Thread Jorge Adriano
I agree with others who mentioned that viewing monads as simply providing a way to sequentialize things or to program imperatively is the wrong way to look at them. snip Yes, Lists are the classical example. That said, the EFFICIENCY of monads is often poorly understood. To state the

Re: State Transformer

2002-01-11 Thread Jorge Adriano
[Obs: most answers I got end up in my pvt e-mail and not in the mailing list... I replyed in pvt to those. I do feel it some cases that is probably accidental as I do it all the time :), and the discussion ends leaving the mailing list. So i'd just like to let you know that I for one am in

State Transformer

2002-01-07 Thread Jorge Adriano
Hi, I'm studying, among other things, Genetic Algorithms and Neural Networks and I decided I'd use haskell to code some simple GAs and NNs along with my study. Well, maybe it was not such a good idea after all, because I've been spending way more time learning more Haskell then GAs and NNs :(

Strictness making it worst?

2001-11-29 Thread Jorge Adriano
Hi, I've just started messing around with strictness. My goal now is understanding when and how to use it. I began with simple examples like making a strict foldl. When trying to sum a list of 6 elements with lazy foldl I'd get a stack space overflow, with a strict foldl I was able to sum

Re: Strictness making it worst?

2001-11-29 Thread Jorge Adriano
Then I tried: sfibac :: IntPos - (IntPos,IntPos) - (IntPos,IntPos) sfibac n (a,b) | n == 0= (a,b) | otherwise = sfibac (n-1) (b, (+b) $! a) I'm sorry I meant: sfibac :: IntPos - (IntPos,IntPos) -

Re: Counting recursive calls

2001-11-13 Thread Jorge Adriano
The functions: f [] w = (w,0) f (x:xs) w = (nextw, steps+1) where (nextw, steps) = f xs (g x w) f2 [] k w = (w,k) f2 (x:xs) k w = f2 xs (k+1) (g x w) f3 [] w = w f3 (x:xs) w = f3 xs (g x w) Oh oh ---

Counting recursive calls

2001-11-11 Thread Jorge Adriano
Hi all, got some questions on recursive functions. I got a simple recursive function (f3) In *some* situations I'll want to know how many recursive calls did it make. I came up with two simple implementations to do that (f1) and (f2) f [] w = (w,0) f (x:xs) w = (nextw, steps+1)

Using the std libraries in Ghc(i)

2001-11-04 Thread Jorge Adriano
How can I use the std functions (listed in the 'Standard Libraries for Haskell 98' documentation) in ghc(i)? I've read the ghc documentation, and seen the several categories (which can be added with '-package category_name') available, but I still don't know how to access functions like

SuSE 7.3

2001-10-09 Thread Jorge Adriano
Está para sair a 22 de Outubro... até eu estou a ficar surpreendido com a evolução destes tipos. Qd penso do 1o Linux que instalei (à cerca de dois anos? - andava eu no 4o ano) sinto-me como aquelas velhas que dizem eu ainda sou do tempo..., err... em que tinha de andar a alterar XF86Config à

Opsss... Sorry (SuSE 7.3)

2001-10-09 Thread Jorge Adriano
I just accidently sent a mail written in portuguese about SuSE 7.3. I'm really sorry, it will not happen again. My apologies J.A. ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe

broken link

2001-10-05 Thread Jorge Adriano
Just thought I'd report that the PolyGP link: http://www.cs.ucl.ac.uk/staff/T.Yu/research.html at the 'Haskell in Practice' section (http://www.haskell.org/practice.html) seems to be broken. J.A. ___ Haskell-Cafe mailing list [EMAIL PROTECTED]

Haskell - C/C++ comunication (sockets/pipes?)

2001-09-25 Thread Jorge Adriano
Hi all, I was thinking about making some GUIs in Qt/KDE for some haskell applications (compiled with ghc). My first idea was to simply run haskell applications with some args using the GUI and get the results from some file or something like that. Anyway someone told me that a better idea