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)