Re: [Haskell-cafe] What is <-

2010-08-08 Thread Jochem Berndsen
michael rice wrote:
> That was my suspicion. So, you can't change horses (monads) in mid-stream.
> 
> A parallel question:
> 
> main = do ...-- in the IO monad
> 
> I know I can have other *do*s in main,
> 
>   if foo
> then do
>   .
>   .
> else do
>  .
>  .
> 
> but must all these other *do*s also be in the same IO monad?

Yes, if you write it like that, they have to. Let us take as an example
(in the IO monad):
f = do
  x <- getLine
  if null x
then y
else z

Desugaring gives:
f =
  getLine >>= (\x -> if null x then y else z)

Since getLine :: IO String and (>>=) :: Monad m => m a -> (a -> m b) ->
m b, we see that
  m = IO
  a = String
So the type of (\x -> if null x then y else z) in the above expression
will be String -> IO b. This means that the parameter x will be of type
String, and "if null x then y else z" will be of type IO b. This implies
that y and z both will be of type IO b. So if you write y and z as a
do-block, this will be in the IO monad.

However, there is no special rule that says "in an expression all
do-blocks must have the same type". E.g., the following is a valid
expression:
  do -- in the Maybe monad.
return Nothing
listToMaybe $ do -- in the [] monad.
  return 4

 What
> determines what monad a *do* is "in"? The first line after the *do*?

Type inference. E.g.
f = do
  return []
will be of type Monad m => m [a].
There is nothing special about monads in this regard, only the
"do"-notation is special: it is desugared as described elsewhere in the
thread and in the Report.

HTH, Jochem

-- 
Jochem Berndsen | joc...@functor.nl
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: [web-devel] Google Summer of Code: BlazeHTML RFC

2010-05-30 Thread Jochem Berndsen

On 05/29/2010 08:05 PM, Gregory Collins wrote:

Matt Parker  writes:


 Q3: Which HTML version would you preferably use?

HTML 5. google summer of code should be about pushing the new and exciting.


Yes, definitely, this should be the default IMO.


+1


--
Jochem Berndsen | joc...@functor.nl
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] MultiParamTypeClasses, FunctionalDependencies and FlexibleInstances using GHCi

2010-05-14 Thread Jochem Berndsen

Julian Fleischer wrote:

Hello,

i'm playin' around with GHCs Haskell and some extensions. I'm already aware of that functional 
dependencies are "very very tricky", but there is something I don't understand about 
there implementation in GHC. I've constructed my own TypeClass "Num" providing a 
signature for (+), having multiple params a, b and c. I'm than declaring a (flexible) Instance for 
Prelude.Num, simply using (Prelude.+) for the definition of my (+) - and it does not work as I 
expect it to.

First, this is the code:

{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, 
TypeSynonymInstances, FlexibleInstances #-}
import qualified Prelude

class Num a b c | a b -> c where
(+) :: a -> b -> c

instance (Prelude.Num x) => Num x x x where
(+) = (Prelude.+)


now if I load it into GHCi and type "3 + 4" i get a whole bunch of 
error-messages.

I do understand that

(3::Prelude.Int) + (4::Prelude.Int)

works, since I've explicitly declared 3 and 4 to be Prelude.Int and there is a 
functional dependency stating that (+) :: a b determines the results type c, by 
the Instance declaration cleary c will be the same as a and b.

Now, if I type

3 + 4

it does not work, and i really don't understand why. If i ask GHCi for 3's type ($ :t 3) it 
will answer "3 :: (Prelude.Num t) => t". But, if 3 and 4 are Prelude.Nums and 
there is an instanfe Num x x x for x of Prelude.Num - than why can't GHC deduce from the 
definitions that 3 and 4, both Prelude.Nums, can be used with (+) since there is an instance 
for Prelude.Num and my class Num - and the result will of course be something of Prelude.Num?


My guess would be, that while 3 and 4 are both of a type instantiating 
Prelude.Num (your terminology "are Prelude.Nums" is quite confusing -- 
Prelude.Num is not a type but a type class), they need not be of the 
same type (e.g., 3 could be of type Integer, and 4 of type Double).


Jochem

--
Jochem Berndsen | joc...@functor.nl
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Rank-2 polymorphism and overloading

2010-04-26 Thread Jochem Berndsen
Thomas van Noort wrote:
> Hello all,
> 
> I'm having difficulties understanding rank-2 polymorphism in combination
> with overloading. Consider the following contrived definition:
> 
> f :: (forall a . Eq a => a -> a -> Bool) -> Bool
> f eq = eq True True
> 
> Then, we pass f both an overloaded function and a regular polymorphic
> function:
> 
> x :: forall a . Eq => a -> a -> Bool
> x = \x y -> x == y
> 
> y :: forall a . a -> a -> Bool
> y = \x y -> True
> 
> g :: (Bool, Bool)
> g = (f x, f y)
> 
> Could someone explain to me, or point me to some reading material, why g
> is correctly typed?
> 
> I understand that x's type is what f expects, but why does y's
> polymorphic type fulfill the overloaded type of f's argument? I can
> imagine that it is justified since f's argument type is more restrictive
> than y's type. However, it requires y to throw away the provided
> dictionary under the hood, which seems counter intuitive to me.

f requires a function that is able to compute, for two values of type a
(which instantiates Eq), a Boolean.

y certainly fulfills that requirement: it does not even require that the
values are of a type instantiating Eq.

This is also well-typed and might or might not be enlightening:

> z :: forall a. Eq a => a -> a -> Bool
> z = y
>
> g :: (Bool, Bool)
> g = (f x, f z) -- note the use of z here instead of y

Jochem
-- 
Jochem Berndsen | joc...@functor.nl

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


Re: [Haskell-cafe] and [] = True; or [] = False

2010-04-26 Thread Jochem Berndsen
Bjorn Buckwalter wrote:
> Dear all,
> 
> Does it make good sense that 'and []' returns 'True' and 'or []'
> returns 'False'? The Haskell Road to Logic, Maths and Programming says
> so:
> 
> "The function or takes a list of truth values and returns True if at
> least one member of the list equals True, while and takes a list of
> truth values and returns True if all members of the list equal True."
> 
> "Should the conjunction of all elements of [] count as true or false?
> As true, for it is indeed (trivially) the case that all elements of []
> are true. So the identity element for conjunction is True. Should the
> disjunction of all elements of [] count as true or false? As false,
> for it is false that [] contains an element which is true. Therefore,
> the identity element for disjunction is False."
> 
> While the above reasoning is fine, and allows straight-forward
> implementations, it isn't extremely convincing. In particular, it
> isn't clear that, while simple, the definitions of the first paragraph
> are the most sensible. Perhaps one of the more mathematically versed
> readers on the Cafe could enlighten me?

The empty sum is regarded to be zero. The empty product is equal to one.
The empty conjunction is True. The empty disjunction is False.

The reason for this is that these are the neutral elements, i.e.
  0 + x = x
  1 * x = x
  True AND x = x
  False OR x = x

This allows some laws to hold also in degenerate cases, and it is quite
useful in general to accept these conventions. An example of such a law is
(∀ x : x ∈ A : P(x)) ∧ (∀ x : x ∈ B : P(x))
 ==
(∀ x : x ∈ A ∪ B : P(x)).

This also works if A or B is empty, provided that we say that the empty
conjunction is true.

In Haskell, we now have that

(and xs) && (and ys)
 ==
and (xs ++ ys),

even if xs or ys is the empty list.

Cheers, Jochem
-- 
Jochem Berndsen | joc...@functor.nl
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Are there any female Haskellers?

2010-03-28 Thread Jochem Berndsen

Alberto G. Corona wrote:
>  The reasons for the sexual differences in mathematical abilities are
> different, because math abilities  are not a -primary- reason for
> survival.  Tools engineering and mastering is. If this is politically
> incorrect I beg you pardon, but this is my honest theory about that. My
> other hobby is evolution and evolutionary psichology.  I really
> recommend to learn about it.

Could you point us to any evidence that supports your assumption that 
there are "sexual differences in mathematical abilities"?


Thanks, Jochem

--
Jochem Berndsen | joc...@functor.nl
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Bytestrings and [Char]

2010-03-22 Thread Jochem Berndsen

David Leimbach wrote:



On Mon, Mar 22, 2010 at 6:10 AM, Johan Tibell <mailto:johan.tib...@gmail.com>> wrote:


On Mon, Mar 22, 2010 at 1:16 PM, Johann Höchtl
mailto:johann.hoec...@gmail.com>> wrote:
 > My question or discussion point: Why not depreciate [Char] altogether
 > and favour of lazy Bytestrings?

A sequence of bytes is not the same thing as a sequence of Unicode
code points. If you want to replace String by something more efficient
have a look at Data.Text.


Slight correction.

A sequence of bytes is exactly the same thing as a sequence of Unicode 
bytes when you use UTF8.  



What is a "Unicode byte"?

Cheers, Jochem

--
Jochem Berndsen | joc...@functor.nl
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] stuck with a sample of "programming in haskell"

2010-03-19 Thread Jochem Berndsen
国平张 wrote:
> Sorry :-). I am using Hugs, anything I did wrong ?
> 

> item :: Parser Char
> item = Parser (\inp -> case inp of

^^^ the second "Parser" should be a P, which is a data constructor.

Cheers, Jochem

-- 
Jochem Berndsen | joc...@functor.nl
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Linguistic hair-splitting

2010-01-27 Thread Jochem Berndsen
Luke Palmer wrote:
> On Wed, Jan 27, 2010 at 11:39 AM, Jochem Berndsen  wrote:
>>> Now, here's the question: Is is correct to say that [3, 5, 8] is a
>>> monad?
>> In what sense would this be a monad? I don't quite get your question.
> 
> I think the question is this:  if m is a monad, then what do you call
> a thing of type m Int, or m Whatever.

Ah yes, I see. It's probably the most common to call this a "monadic
value" or "monadic action". As Daniel pointed out, the type constructor
itself is called a "monad" (e.g., Maybe).

Jochem

-- 
Jochem Berndsen | joc...@functor.nl
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Linguistic hair-splitting

2010-01-27 Thread Jochem Berndsen
Andrew Coppin wrote:
>> 7 is a number. 7 is an integer, and integers are numbers.
> 
> 7 is not a field. 7 is an element of [at least one] field, but 7 itself
> is not a field.
> 
> 7 is not a group. 

Why not? It might be useful to use the notation '7' for the cyclic group
with 7 elements.

> 7 is a member of the set of integers, but the set of
> integers is not a group either. The set of integers form a group when
> taken together with the addition operator. (And, actually, forms
> another, different, group when taken with the multiplication operator.)

The integers endowed with the usual multiplication is not a group. (The
only invertible elements of this monoid are 1 and -1.)

> Now, here's the question: Is is correct to say that [3, 5, 8] is a
> monad? 

In what sense would this be a monad? I don't quite get your question.

Cheers, Jochem

-- 
Jochem Berndsen | joc...@functor.nl

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


Re: [Haskell-cafe] Design question, HTML for GUIs?

2010-01-10 Thread Jochem Berndsen
Günther Schmidt wrote:
> as probably most people I find the GUI part of any application to be the
> hardest part.
> 
> It just occurred to me that I *could* write my wxHaskell desktop
> application as a web app too.
> 
> When the app starts, a haskell web server start listening on localhost
> port 8080 for example and I fire up a browser to page localhost:8080
> without the user actually knowing too much about it.
> 
> Is that a totally stupid idea?

No, this is not (necessarily) a stupid idea. In fact it might be a good
idea in a lot of cases.

A downside is, that you lose the functionality for user access control
provided by the OS on multi-user machines (i.e., other users working on
the same machine can connect to localhost:8080 too). This might or might
not be a concern for you.

Regards, Jochem
-- 
Jochem Berndsen | joc...@functor.nl | joc...@牛在田里.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Review request for my permutations implementation

2010-01-07 Thread Jochem Berndsen
CK Kashyap wrote:
> I've written this piece of code to do permutations -

First off, this is a recurring topic. If you search the archives, you'll
find some more topics about it.

> perms :: String -> [String]

Why this type? Since a String is just a list of Char, and you don't use
the fact that you're actually using a list of characters. It's better to
keep this function generic, and say

  perms :: [a] -> [[a]]

> perms []= []

I don't think this is what you expect or want. I would consider a
permutation of X to be a bijection X -> X. The number of bijections X ->
X when X is empty, is in fact 1. So I think

  perms [] = [[]]

> perms (x:[])= [[x]]

I think you can drop this case if you do perms [] = [[]]. (Didn't prove
it, though.)

> perms (x:xs)= concat (f [x] (perms xs))

A small stylistic issue: Normally I'd write a space before the '='.

> spread :: String -> String -> [String] -- interpolate first string at various 
> positions of second string

This function becomes easier if you define it like

  spread :: a -> [a] -> [[a]]

since you only use it in that way.

> spread str1 str2 = _spread str1 str2 (length str2)
> where
> _spread str1 str2 0= [str1 ++ str2]
> _spread str1 str2 n= [(take n str2) ++ str1 ++ (drop n str2)] ++ (_spread 
> str1 str2 (n-1))
> 
> f xs = map (spread xs)

There is a better way to write spread, something like

  spread str1 xs = zipWith (\x y -> x ++ str1 ++ y)
   (inits xs)
   (tails xs)

with inits and tails from Data.List.


HTH, regards, Jochem
-- 
Jochem Berndsen | joc...@functor.nl | joc...@牛在田里.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] lawless instances of Functor

2010-01-04 Thread Jochem Berndsen
Steffen Schuldenzucker wrote:
> data Foo a = Foo a
> 
> instance Functor Foo where
> fmap f (Foo x) = Foo . f . f $ x

I think this doesn't typecheck.

Cheers, Jochem

-- 
Jochem Berndsen | joc...@functor.nl | joc...@牛在田里.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] powering of new types

2009-12-22 Thread Jochem Berndsen
slemi wrote:
> oh well thats pretty straight-forward:)
> 
> the next thing i don't understand is how ghci turns 1 into (Scalar 1).
> 1 == (Scalar 1) returns True, which is logical in a way (NOT), but if i
> change the type definition to
> data Matrix a = Matr {unMatr :: [[a]]} | Lol a | Scalar a
> then
> 1 == (Scalar 1) still returns True, but
> 1 == (Lol 1) returns False, no matter in what order I put them in the
> definition... o.O

Numeric literals in Haskell are overloaded. 1 really means
fromInteger 1. The function fromInteger is defined by instances of Num.
This is why you can use a numeric literal wherever your program expects
a Double, Int, Integer, and so on. This includes your own type. You have
probably defined fromInteger = Scalar for your type.

Cheers, Jochem

-- 
Jochem Berndsen | joc...@functor.nl | joc...@牛在田里.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Pattern matching, and bugs

2009-12-18 Thread Jochem Berndsen
András Mocsáry wrote:
> *My concern*
> is about predictable failure of sw written in Haskell.
> To illustrate it let's see a Haskell pattern matching example:

> And in Haskell pattern matching:
> 
> switch 1 =  "Unchecked"
> 
> switch 2 =  "Checked"
> 
> switch 3 =  "Unknown"
> 
> 
> Let's say, these are clearly defined states of some objects.
> Then let's say something unexpected happens: x gets something else than 0 1
> 2.
> Now we have a problem, which is most generally fixed in these ways:
> 
> switch 1 =  "Unchecked"
> 
> switch 2 =  "Checked"
> 
> switch 3 =  "Unknown"
> 
> switch x =  "Nothing"
> 
> These general ways really avoid this particular crash, but does something
> real bad to the code in my opinion.

Agreed. The real cause of the problem is that the programmer didn't
prove that x is in {1,2,3} when calling switch.

> Below are some cases x can go wrong:
> *1. The bad data we got as 'x', could have came from an another part of our
> very program, which is the REAL CAUSE of the crash, but we successfully hide
> it.*
> *
> Which makes it harder to fix later, and thus eventually means the death of
> the software product. Eventually someone has to rewrite it.
> Which is economically bad for the company, since rewriting implies increased
> costs.

Yes.

> 2. The bad data we got as 'x', could also could have come form a real
> word object,
> we have underestimated, or which changed in the meantime.

You should not assume that your input is correct in fault-tolerant programs.

> 3. This 'x' could have been corrupted over a network, or by 'mingling' or by
> other faulty software or something.

Unlikely. There is nothing you can do about this, though.


> Point 1:
> If we allow ourself such general bugfixes, we eventually kill the ability of
> the project to 'evolve'.
> 
> Point 2:
> Programmers eventually take up such 'arguably bad' habits, thus making
> harder to find such bugs.
> 
> Thus it would be wiser to tell my people to never write Default cases, and
> such general pattern matching cases.

It is a better idea to use the type system to prevent this kind of bugs.
In this particular case, it's better to try to have a datatype like
data X = One | Two | Three

> *
> Which leads to the very reason I wrote to you:
> 
> I want to propose this for Haskell prime:
> 
> I would like to have a way for Haskell, not to crash, when my coders write
> pattern matching without the above mentioned general case.
> Like having the compiler auto-include those general cases for us,
> but when those cases got hit, then* instead of crashing*, it *should **report
> some error* on *stdout *or *stderr*.
> (It would be even nicer if it cold have been traced.)

And, how would it continue?
Suppose that we have the function
head :: [a] -> a
head (x:_) = x

What would you propose that would happen if I call head [] ? Print an
error on stderr, say, but what should it return? Surely it cannot make
an value of type "a" out of thin air?

Nowadays, head [] crashes the program, and you get an error message to
standard error.

> This is very much like warning suppression, just that it's crash
> suppression, with the need of a report message of course.

This is already possible with exception handling.

> *I would like to hear your opinion on this.*

I don't think it can be implemented in a sane way, or that it's a good
idea to suppress this silently, when an explicit solution already exists.

> I also think, that there are many similar cases in haskell, where not
> crashing, just error reporting would be way more beneficial.
> In my case for server software, where network corrupted data,
> ( and data which has been 'tampered with' by some 'good guy' who think he's
> robin hood if he can 'hack' the server )
> is an every day reality.

You should validate your data in any case. You may even turn a DoS
attack into a "real" security problem with your "solution".

Cheers, Jochem

-- 
Jochem Berndsen | joc...@functor.nl | joc...@牛在田里.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: [Haskell] ANN: readline-statevar-1.0.1.0

2009-12-06 Thread Jochem Berndsen
Jochem Berndsen wrote:
> nerds

This was a friend of mine trying to be funny.

Apologies, Jochem

-- 
Jochem Berndsen | joc...@functor.nl | joc...@牛在田里.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: [Haskell] ANN: readline-statevar-1.0.1.0

2009-12-06 Thread Jochem Berndsen
nerds
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell-Newbie and Char-Function

2009-12-05 Thread Jochem Berndsen
MeAdAstra wrote:
> Hi guys,
> I only started learning Haskell some days ago. Maybe one of you can give me
> a hint on how to implement a function that needs a character in the range
> (a,b,...z) and an integer number k and returns the k-next neighbor of the
> character? For example, fct a 5 would result in output f.

You might want to use the functions ord and chr from Data.Char, and the
mod function from the Prelude.

Regards, Jochem

-- 
Jochem Berndsen | joc...@functor.nl | joc...@牛在田里.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Mystery operator?

2009-11-30 Thread Jochem Berndsen
michael rice wrote:
> From: http://www.haskell.org/haskellwiki/Blow_your_mind#Polynomials
> 
>   -- splitting in two (alternating)
>   -- "1234567" -> ("1357", "246")
>   -- the lazy match with ~ is necessary for efficiency, especially enabling 
> processing of infinite lists
>   foldr (\a ~(x,y) -> (a:y,x)) ([],[])
> 
> This works but can't find (~) operator anywhere. Please explain or site a 
> reference.

This is called a "lazy pattern".
See:
http://www.haskell.org/tutorial/patterns.html
section 4.4

Cheers, Jochem
-- 
Jochem Berndsen | joc...@functor.nl | joc...@牛在田里.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] hackage is down.

2009-11-02 Thread Jochem Berndsen
??? ?? wrote:
> 
>> No no no!  Why not download the normal (signed) cabal list from the
>> DHT (and optionally directly from hackage.haskell.org)?  These are all
>> the packages that would appear on the website.  Why serve any other
>> content?  All nodes in the DHT may check and make sure the file (or
>> fragment) being served is properly signed.
>>
>> Any desire for popularity or tagging capability should be separate.
>>   
> Because single single hackage private key can be bruteforsed or stolen
> far easier than lots and lots keys of random people.

You only need to compromise one well-trusted key to compromise the system.

Cheers, Jochem

-- 
Jochem Berndsen | joc...@functor.nl | joc...@.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] hackage is down.

2009-11-01 Thread Jochem Berndsen
On Sun, Nov 01, 2009 at 07:58:00AM -0600, Thomas Hartman wrote:
> http://hackage.haskell.org

Hackage is down currently, I am seeding the torrent by mauke from IRC on 
http://mauke.ath.cx/tmp/2009-10-19-hackage-archive.torrent

Cheers, Jochem
-- 
Jochem Berndsen | joc...@functor.nl | joc...@牛在田里.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] x -> String

2009-10-16 Thread Jochem Berndsen
Andrew Coppin wrote:
> Is there any way that you can turn an arbitrary Haskell value into a
> string?

No, the only values of type
a -> String
are the constant functions and _|_.

> I rephrase: There *is* a way to turn arbitrary values into strings. I
> know there is, because the GHCi debugger *does* it. The question is,
> does anybody know of an /easy/ way to do this?

No. GHCi does not always do this:

Prelude Data.Ratio> let plus1 = (+1)
Prelude Data.Ratio> plus1

:1:0:
No instance for (Show (a -> a))
  arising from a use of `print' at :1:0-4
Possible fix: add an instance declaration for (Show (a -> a))
In a stmt of a 'do' expression: print it
Prelude Data.Ratio>


> Basically, I'm writing a mutable container implementation. It can hold
> any type of data, but it would massively aid debugging if I could
> actually print out what's in it. On the other hand, I don't want to
> alter the entire program to have Show constraints everywhere just so I
> can print out some debug traces (and then alter everything back again
> afterwards once I'm done debugging).

This is not advisable, as you see.

> Anybody know of a way to do this? (As it happens, the values I'm testing
> with are all Showable anyway, but the type checker doesn't know that...)

What is the problem with adding a function
showMyContainer :: (Show a) => Container a -> String
?
In this case you can show your container (for debugging purposes), but
only if you have Showable elements in your container.

Cheers, Jochem

-- 
Jochem Berndsen | joc...@functor.nl | joc...@牛在田里.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] is proof by testing possible?

2009-10-12 Thread Jochem Berndsen
Neil Brown wrote:
> Dan Piponi wrote:
>> On Mon, Oct 12, 2009 at 10:42 AM, muad  wrote:
>>  
>>> Is it possible to prove correctness of a functions by testing it? 
>> consider a function of signature
>>
>> swap :: (a,b) -> (b,a)
>>
>> We don't need to test it at all, it can only do one thing, swap its
>> arguments. (Assuming it terminates.)
>>   
> swap = undefined
> 
> Terminates and does not swap its arguments :-)  What do free theorems
> say about this, exactly -- do they just implicitly exclude this
> possibility?

Normally, one presumes that "undefined" (id est, calling "error") is
equivalent to looping, except that calling "error" is pragmatically
speaking better: it is nicer to the caller of your function (they/you
get to see a somewhat more descriptive error message instead of 100% CPU
without any results).

Regards, Jochem

-- 
Jochem Berndsen | joc...@functor.nl | joc...@牛在田里.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] type inference question

2009-10-08 Thread Jochem Berndsen
minh thu wrote:
> Also, I'd like to know why
>
> id id True
>
> is permitted but not
>
> (\f -> f f True) id

If you want to do this, answer the question "what is the type of (\f ->
f f True)"?
You can do this, by the way, using rank-2 types:
> {-# LANGUAGE Rank2Types, PatternSignatures #-}
> thisIsAlwaysTrue = (\ (f :: forall a. a -> a) -> f f True) id

Cheers, Jochem
-- 
Jochem Berndsen | joc...@functor.nl | joc...@牛在田里.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell for Physicists

2009-09-30 Thread Jochem Berndsen
Khudyakov Alexey wrote:
> В сообщении от 30 сентября 2009 21:42:57 ed...@ymonad.com написал:
>> Hi,
>>
>> I will give a seminar to physicists at USP (Universidade de São Paulo,
>>  Brazil) university and they asked me for a good title, something that can
>>  attract physicists. Anyone has some suggestions? (Will be a seminar about
>>  the use of Haskell to substitute C or Fortran
>> in a lot of tasks, and how it can be used in some problems instead of
>> Matlab, Mathematica, etc.)
>>
> What area of physics? They all face somewhat different problems from 
> computation.
> 
> Could you publish your slides from seminar (if any) and even if they are in 
> Spanish (nothing is impossible for man with a dictionary)

And what if they're in Portuguese? ;)

Cheers, Jochem

-- 
Jochem Berndsen | joc...@functor.nl | joc...@牛在田里.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] convert a list of booleans into Word*

2009-09-30 Thread Jochem Berndsen
Bulat Ziganshin wrote:
> Hello Paul,
>
> Wednesday, September 30, 2009, 1:18:03 PM, you wrote:
>
>> I haven't found a function in hackage or in the standard library that
>> takes a list of booleans (or a list of 0s and 1s, or a tuple of booleans
>> or 0s and 1s) and outputs a Word8 or Word32.
>
> sum . zipWith (*) (map (2^) [0..])

I'd turn this into
> sum . zipWith (*) (iterate (2*) 1)
, but it's probably not very important.

Regards, Jochem
-- 
Jochem Berndsen | joc...@functor.nl | joc...@牛在田里.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] I read somewhere that for 90% of a wide class of computing problems, you only need 10% of the source code in Haskell, that you would in an imperative language.

2009-09-30 Thread Jochem Berndsen
Deniz Dogan wrote:
> 2009/9/30 Andrew Coppin :
>> (Mr C++ argues that homo sapiens fundamentally think in an imperative way,
>> and therefore functional programming in general will never be popular.
> 
> Sounds more like Mr C++ fundamentally thinks in an imperative way
> because that's what he is used to.

This may or may not be true. It would be interesting to see some
research on this. Without that, I think we cannot decide either way.
Cheers, Jochem

-- 
Jochem Berndsen | joc...@functor.nl | joc...@牛在田里.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] yi-editor: Duplicate instance declarations

2009-09-27 Thread Jochem Berndsen
Nicolas Pouillard wrote:
> Excerpts from Marcelo Sousa's message of Sun Sep 27 14:13:43 +0200 2009:
>> Hey guys,
>>
>> I'm trying to install yi using cabal but I got this error. Any ideas
>> how to solve it?!
>> I'm using ghc-6.10.1 and cabal-install version 0.6.2 using version
>> 1.6.0.2 of the Cabal library.
> 
> This means that you either have to downgrade data-accessor, or trash out the
> Category instance in Yi/Prelude.hs line 182.
> 

FYI: I had the same problem this morning. Using data-accessor 0.2.0.2
worked.

Regards, Jochem

-- 
Jochem Berndsen | joc...@functor.nl | joc...@牛在田里.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Problem on existential type.

2009-09-04 Thread Jochem Berndsen
Miguel Mitrofanov wrote:
> Your data type GridWidget doesn't have a parameter, yet you use it like
> it has one.
> 
>> data GridWidget = forall widget. (WidgetClass widget) => GridWidget
>> widget
> ^
> |
> NB:-+

This is allowed as long as you have enabled the ExistentialTypes
extension. This declares a so-called existential type, see the wiki for
details, http://www.haskell.org/haskellwiki/Existential_types .

Note that the second occurrence of "GridWidget" defines a data
constructor, not a type constructor.

Cheers, Jochem

-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Get data from HTML pages

2009-08-31 Thread Jochem Berndsen
José Romildo Malaquias wrote:

> Currently the application has an option to indirectly import movie data
> from web pages. For that first the user should access the page in a web
> browser. Then the user should copy the rendered text in the web browser
> into an import window in my application and click an "import" button. In
> response the application parses the given text and collects any relevant
> data it knows about, using regular expressions.
> 
> For instance, to get the director information from a movie in the
> AllCenter web site I use the following regular expression:
> 
>^Direção:\s+(.+)$
> 
> I want to modify this scheme in order to eliminate the need to copy the
> rendered text from a web browser. Instead my application should download
> and parse the HTML page directly.
> 
> Which libraries are available in Haskell that would make it easy to get
> content information from a HTML document, in the way described above?

To parse HTML documents, I've had success with TagSoup in the past. You
can take a look at the HTTP package to download the HTML from the
server. Both packages are available from Hackage.

HTH, Jochem

-- 
Jochem Berndsen | joc...@functor.nl
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Leaner Haskell.org frontpage

2009-07-09 Thread Jochem Berndsen
hask...@kudling.de wrote:
> Most people feel overwhelmed when confronted with more than 7+-2 items:
> http://www.smashingmagazine.com/2007/10/09/30-usability-issues-to-be-aware-of/

This refers to the number of items/things people can remember in their
short-time memory. This has nothing to do with the maximum number of
menu items you should use. There is of course a limit, but there is no
reason to limit it to 7+-2.

Cheers,
-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell Platform on Ubuntu

2009-07-07 Thread Jochem Berndsen
Erik de Castro Lopo wrote:
>> GHC in Ubuntu is a pain!
> 
> The same is also currently true for GHC on Debian stable and
> testing. Debian unstable is also a bit broken.

I only use Debian Stable, but I don't find it very hard to use. I just
use the binary packages from www.haskell.org.
That said, there has been a lot of activity on the debian-haskell
mailing list lately (debian-hask...@lists.debian.org) so there will
probably some progress quite soon! (Not sure if it will be in time for
Ubuntu 9.10 though).
Cheers,

-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ORM for haskell?

2009-07-03 Thread Jochem Berndsen
Chris Eidhof wrote:
> I've something working that sort of does this. You define your model in
> the following way:
> 
> data User = User {name :: String, password :: String, age :: Int, post
> :: BelongsTo Post}
> data Post = Post {title :: String, body :: String}
> 
> Then there's some boilerplate code (that ultimately will be generated by
> TH), and from that moment on you can do things like this:
> 
> test = do
>   conn <- connectSqlite3 "example.sqlite3"
>   runDB conn $ do
> user <- fromJust <$> find typeUser 1
> user' <- fillBelongsTo user relPost
> return (post user')


> By default, no relations will be fetched, but by doing the fillBelongsTo
> the user will be updated. I currently have support for new, update and
> find. All of this code is very alpha, and only works using HDBC and
> Sqlite3, but still.

So in this example, both user and user' are of type User, but if I ask
for "post user", this is undefined?
I have done something similar as you, except that I filled the related
field with an unsafePerformIO fetching the related data from the database.

Regards,

-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Monoid wants a (++) equivalent

2009-07-01 Thread Jochem Berndsen
a...@spamcop.net wrote:
> G'day all.
> 
> Quoting John Meacham :
> 
>> (+>) seems to imply to me that the operator is non-associative. Something
>> like (<>) or (<+>) would be better.
> 
> I tend to agree.  Moreover, and I realise this may be a losing battle,
> I want (++) to be the generic operator.

I totally agree. (+>) is too asymmetric for my taste, like (>>=) and
(*>) it suggests asymmetry between the arguments. (++) is symmetric and
suggests an associative operator to me.

-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Another question about unsafePerformIO

2009-06-25 Thread Jochem Berndsen
Matthias Görgens wrote:
> I have a program that optimizes train schedules.  It employs an
> external solver for Integer Linear Programs.  The solve function has
> the following type:
> 
>> solve :: Constraints -> IO (Maybe Solution)
> 
> And this works.  However, my external solver also behaves like a pure
> function from input to output.  I wonder whether this guarantee should
> be reflected in the type system.  I'd also appreciate if the compiler
> would be able to eliminate some calls to the solver.
> 
>> solvePure :: Constraints -> Maybe Solution
>> solvePure = unsafePerformIO . solve
> 
> Is this a good idea?

This is safe as long as there are no side effects, and not depend on its
environment (e.g. don't open files, read from environment variables).

In general, functions that do not IO should not have IO in their type
signature, because this will contaminate calling functions unnecessarily.

Adding 'unsafePerformIO' will work, but a better idea might be to
understand why your solver has IO in its type signature. Is this because
of FFI calls? You can remove IO in FFI calls if they are free from side
effects as well.

Regards,

-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Using unsafePerformIO safely

2009-06-24 Thread Jochem Berndsen
(Also taking this to the -cafe)

Hector Guilarte wrote:
> > I made a GCL compiler using Alex and Happy and now I'm making the
> > interpreter to that program. Here's the deal:
> >
> > First of all, I'm no expert in the usage of monads. Now:
> >
> > Whenever a "show" instruction is found in any GCL program while the
> > interpretation is being done it is supposed to print on the stdout the
> > string or the aritmetic expresion it was called with, so I guessed I
need to
> > run an IO operation and continue the interpretation of my program. I
managed
> > to do this using unsafePerformIO and `seq` like is shown below. My
question
> > is: Is it safe to use it this way? So far it is working great, but I
need to
> > be sure I'm using it in a "safe" way. Like I said, I'm no expert in
monads
> > and the System.IO.Unsafe documentation says:
> >
> > "
> > *unsafePerformIO* ::
> >
IO<http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-IO.html#t%3AIO>a
> > -> a
> > This is the "back door" into the
> >
IO<http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-IO.html#t%3AIO>monad,
> > allowing
> >
IO<http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-IO.html#t%3AIO>computation
> > to be performed at any time. For this to be safe, the
> >
IO<http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-IO.html#t%3AIO>computation
> > should be free of side effects and independent of its
> > environment.
> > "
> >
> > I don't know if the IO computation I'm doing is free of side effects and
> > independent of its enviroment :s. (is just hPutStr stdout )

Well, writing to the standard output is certainly a side effect. (This
does not mean that you cannot use unsafePerformIO. The compiler,
however, may assume that any value is free from side effects. This means
that you could get, in theory, less or more output from your program
than you want. In this sense it is not "safe".)

> > Also I've read something about my code not being executed for sure or
> > something like that. Can somebody check the code and tell me if I'm
"safe"
> > with it?

It's "safe" in the sense that it probably won't blow up your computer.
It may also work. On the other hand, I would not recommend using
unsafePerformIO in this way.

I see two possibilities for resolving this issue:
* (ugly) run your GCL (Guarded Command Language?) interpreter in the IO
monad, and using "print"/"putStr"/... whenever you encounter a 'show'
statement in the GCL program.
* (nicer/Haskellier) adapt your interpreter such that it returns a list
of Strings to output. You have then a purely functional interpreter, and
in the main function of your program you can print this list. This will
be lazily evaluated as the GCL program runs. You now have a very nice
separation of clean, pure code, and impure code in the IO monad (your
"main" function, which can be pretty small in your case). To avoid
boilerplate, you can use the Writer monad, for example, but others may
have better suggestions.

Kind regards,

--
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] coding standard question

2009-06-22 Thread Jochem Berndsen
Jules Bean wrote:
> Magnus Therning wrote:
>> Also from experience, I get a good feeling about software that
>> compiles without warnings.  It suggests the author cares and is
>> indicative of some level of quality.
> 
> In contrast, I find almost all the GHC warnings to be useless, and
> therefore turn them off. I don't find they have a significant
> correlation with code quality.
> 
> YMMV :)

I strongly disagree with this.
There is a huge difference between

f (x:xs) = ...

and

f (x:xs) = ...
f [] = error "f: we expect a nonempty list"

The reason for this is that in the second case you express to somebody
who reads your code (including yourself) that this omission was intentional.

The same holds for other warnings (although I sometimes am annoyed by
the shadowing warnings, I agree :).

My default is to start developing, then adding -Wall -Werror and make it
compile again.

Regards,

-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Code walking off the right edge of the screen

2009-06-20 Thread Jochem Berndsen
Antoine Latter wrote:
> On Sat, Jun 20, 2009 at 1:05 PM, Deniz Dogan wrote:
>> I (too) often find myself writing code such as this:
>>
>> if something
>>  then putStrLn "howdy there!"
>>  else if somethingElse
>>  then putStrLn "howdy ho!"
>>  else ...
>>
>> I recall reading some tutorial about how you can use the Maybe monad
>> if your code starts looking like this, but as you can see, that
>> doesn't really apply here. "something" and "somethingElse" are simply
>> booleans and each of them have different actions to take if either of
>> them is True.
>>
>> So how do I make code like this prettier?
> 
> I'm not entirely sure if this is haskell'98, but GHC seems to support
> this sort of layout:
> 
> main = do
>   
> 
>   if something then someOtherComputation else do
> 
>   
> <<<<<

IMHO, this is ugly and counterintuitive; I like having a single "point
of exit" (to use an imperative programming term) of a function. Your
suggestion is equivalent to

someComputation;
if something then begin
someOtherComputation;
    exit;
end;
more;

in, say, Pascal. This obscures the fact that "more;" is sometimes/often
not executed. (You could argue the same about exceptions, but they are a
necessary evil ;-).

Regards,

-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ANNOUNCE: hyena

2009-06-18 Thread Jochem Berndsen
Johan Tibell wrote:
> I am pleased to announce the first release of hyena, a library for building
> web servers, based on the work on iteratee style I/O by Oleg Kiselyov.
> 
> The library allows you to create web servers that consume their input
> incrementally, without resorting to lazy I/O. This should lead to more
> predictable resource usage.
> 
> This is an early alpha release so expect the API to change in the future. In
> particular, I'm working on converting the current definition of
> iteratees/enumerators used to the one in the iteratee package [1]. I decided
> to release this version, based on a simple left fold, due to requests by
> several people who already started using hyena.
> 
> Get it:
> 
>cabal install hyena
> 
> And on Hackage:
> 
>http://hackage.haskell.org//package/hyena
> 
> 1. http://hackage.haskell.org/package/iteratee

Cool! I will certainly look into it.

Cheers,

-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: Fwd: [Haskell-cafe] curious about sum

2009-06-14 Thread Jochem Berndsen
Alberto G. Corona wrote:
> Once more I forgot to send my messages to the haskell cafe list. All the
> rest of the list which I´m suscribed to, send  the mail replies to the list
> automatically, but this doesn´t. Please, can this be changed?.

This comes up every so often, but I would be against this. Your e-mail
client should support mailing lists.

> this version of foldl IS strict:
> 
> foldlStrict f z0 xs0 = lgo z0 xs0
> where
>lgo z [] =  z
>lgo z (x:xs) =let t= f z x in t `seq` lgo t xs
> 
> main= print $  foldlStrict (+) 0 [1..100]
> 5050
> 
> so the garbage collector do the job in freeing the consumed part of the
> list

This is correct; the function you defined is equivalent to foldl' in
Data.List, if I'm not mistaken.

Regards,
-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell - string to list isusses, and more

2009-06-14 Thread Jochem Berndsen
Gjuro Chensen wrote:
> startsWithUpper :: String -> Bool
> startsWithUpper []= False
> startsWithUpper string =
>   if myIsUpper(head(string)) then True 
>   else False

It is very good that you caught the issue of taking the head of an empty
list :)
I saw here and also below, that you did things like
if P then True else False
You can shorten this to 'P'.

Also, normally Haskellers like to pattern match, changing the second
clause of your function into
startsWithUpper (x:xs) = myIsUpper x

> check :: [String] -> Bool
> check []=False

Why is this False and not True? Certainly in the empty string all words
start with an uppercase letter, don't they? (If it's True, you can even
remove this clause, and let the other one take care of the rest.)

Regards,

-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell - string to list isusses, and more

2009-06-14 Thread Jochem Berndsen
Deniz Dogan wrote:
> 2009/6/14 Jochem Berndsen :
>> Toby Miller wrote:
>>> caps1 s = all (\x -> isUpper (head x)) (words s)
>> This seems fine, but you need to check that words never returns a list
>> containing the empty string (otherwise `head' will fail).
> 
> Is there any such case? I was thinking about that as well, but
> couldn't think of any case where head would be called on an empty
> list.

Not that I know of; but I tested this in order to make sure that I
didn't overlook something obvious. (At least, it's a potential issue
that we need to check, since `head' is partial.)

Regards,

-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell - string to list isusses, and more

2009-06-14 Thread Jochem Berndsen
Toby Miller wrote:
> Here's what I came up with.  I especially like the 2nd version, even
> though it's longer, as it seems very declarative.
> 
> caps1 s = all (\x -> isUpper (head x)) (words s)
> 
> caps2 s = all startsWithUpper (words s) where
> startsWithUpper w = isUpper (head w)
> 
> 
> I'm also fairly new to Haskell, so I would appreciate feedback from the
> more experienced.

This seems fine, but you need to check that words never returns a list
containing the empty string (otherwise `head' will fail).

I prefer in this case a point free style though, but some might disagree.

Cheers,
-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell - string to list isusses, and more

2009-06-14 Thread Jochem Berndsen
Gjuro Chensen wrote:
> Hello everyone! 
> 
> Im a Haskell newbie, and Ive have few unanswered questions. For someone more
> experienced (at least I think so) its a very simple task, but I just cant
> get a grip on it and its pretty frustrating. It wouldn't be that bad if I
> haven't browse thru bunch of pages and tutorials and still nothing...
> The problem is: take a string, and if every words starts with uppercase
> letter then print yes, else no.
> Forum Text Bold -> yes
> Frog image File -> no
> 
> Ive had my share of approaches to this, but I just cant make it work. 
> Standard one seemed the most simple:
> 
> search :: String -> String
> search [] = []
> 
> 
> and then use words (splits string on space) to split the string so I could
> get a list and go through it recursively. But how to apply words to entered
> string in this form? 
> 
> To find the first letter I came up with: first = take 1 (head x). And
> compare it with elem or ASCII values to determine if its upper case.

The idea of using `words' is very good.
If we want to use a bottom-up approach, we should have a function that
determines if a word starts with an upper-case letter, i.e. a function
of type
startsWithUppercase :: String -> Bool
startsWithUppercase  = ...

(Hint: look at 'isUpper' from Data.Char)

Now we need a way to see if for each word, some predicate is satisfied.
There is a standard function for this, "all".
You can also do this by using "map" and "and".

The resulting function can be very concise if you get the hang of it :)

Regards,
-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] curious about sum

2009-06-13 Thread Jochem Berndsen
Daniel Fischer wrote:
> Am Samstag 13 Juni 2009 17:00:36 schrieb Jochem Berndsen:
>> Deniz Dogan wrote:
>>> 2009/6/13 Jochem Berndsen :
>>>> Keith Sheppard wrote:
>>>>> Is there any reason that sum isn't strict? I can't think of any case
>>>>> where that is a good thing.
>>>>>
>>>>> Prelude> sum [0 .. 100]
>>>>> *** Exception: stack overflow
>>>> It is useful if the (+) is nonstrict; although I cannot think of any
>>>> useful mathematical structure where (+) would be nonstrict.
>>> I remember needing a non-strict sum at least once, but I do not
>>> remember the exact application. But imagine having a (very) long list
>>> of numbers and you want to do A if the sum exceeds a small number,
>>> otherwise B.
>>>
>>> if sum [0..10] > 10 then A else B
>>>
>>> However, this idea didn't work, because of strictness.
>> You can only do such things if you know that all entries of your list
>> are nonnegative. That requires a custom solution anyway (not to mention
>> the fact that to determine whether x > 10 or not, we need to explicitly
>> compute x).
> 
> Well, if you have lazy Peano numbers of any kind, you know that all entries 
> are non-
> negative and you needn't evaluate x fully to determine whether it's > 10. 
> Isn't that the 
> point why one would use lazy numbers at all?

Yes. (That's what I meant with 'custom solution', using Peano numbers
instead of Ints or Integers.)

Regards,

-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] curious about sum

2009-06-13 Thread Jochem Berndsen
Deniz Dogan wrote:
> 2009/6/13 Jochem Berndsen :
>> Keith Sheppard wrote:
>>> Is there any reason that sum isn't strict? I can't think of any case
>>> where that is a good thing.
>>>
>>> Prelude> sum [0 .. 100]
>>> *** Exception: stack overflow
>> It is useful if the (+) is nonstrict; although I cannot think of any
>> useful mathematical structure where (+) would be nonstrict.
> 
> I remember needing a non-strict sum at least once, but I do not
> remember the exact application. But imagine having a (very) long list
> of numbers and you want to do A if the sum exceeds a small number,
> otherwise B.
> 
> if sum [0..10] > 10 then A else B
> 
> However, this idea didn't work, because of strictness.

You can only do such things if you know that all entries of your list
are nonnegative. That requires a custom solution anyway (not to mention
the fact that to determine whether x > 10 or not, we need to explicitly
compute x).

Regards,

-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] curious about sum

2009-06-13 Thread Jochem Berndsen
Keith Sheppard wrote:
> Is there any reason that sum isn't strict? I can't think of any case
> where that is a good thing.
> 
> Prelude> sum [0 .. 100]
> *** Exception: stack overflow

It is useful if the (+) is nonstrict; although I cannot think of any
useful mathematical structure where (+) would be nonstrict.

Regards,

-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] exporting Data.ByteString functions via FFI

2009-06-12 Thread Jochem Berndsen
kenny lu wrote:
> Hi,
> 
> I was trying to write a FFI wrapper for my Haskell program which manipulates
> 
> ByteString. But I am unable to compile/link it.
> 
> 
> Here is the toy program.
> 
> {-# LANGUAGE ForeignFunctionInterface #-}
> 
> module B where
> 
> import Foreign.C.Types
> import Foreign.C.String
> import qualified Data.ByteString as BS
> 
> rev :: BS.ByteString -> BS.ByteString
> rev bstr = BS.reverse bstr
> 
> rev_hs :: CString -> IO CString
> rev_hs cstr =
> do { bstr <- BS.packCString cstr
>; let bstr' = rev bstr
>; cstr' <- newCString (show bstr')
>; return cstr'
>}
> 
> foreign export ccall rev_hs :: CString -> IO CString
> 
> 
> And here is the C counter-part.
> 
> #include "B_stub.h"
> #include 
> 
> int main(int argc, char *argv[]) {
>   char *str;
>   hs_init(&argc, &argv);
> 
>   str = rev_hs("it works.");
>   printf("Rev: %s\n", str);
> 
>   hs_exit();
>   return 0;
> }
> 
> Compiling B.hs alone seems fine, but errors popped up when I was trying to
> compile/link it with C.
> 
> $ ghc -c -O B.hs
> 
> $ ghc -optc-O test_b.c B.o B_stub.o -o test_b
> Undefined symbols:
>   "___stginit_bytestringzm0zi9zi1zi4_DataziByteString_", referenced from:
>   ___stginit_Lib_ in B.o
>   "_bytestringzm0zi9zi1zi4_DataziByteString_zdwreverse_info", referenced
> from:
>   _s19w_info in B.o
>   "_bytestringzm0zi9zi1zi4_DataziByteStringziInternal_zdwshowsPrec_info",
> referenced from:
>   _s19v_info in B.o
>   "_bytestringzm0zi9zi1zi4_DataziByteStringziInternal_zdwshowsPrec_closure",
> referenced from:
>   _Lib_zdwa_srt in B.o
>   "_bytestringzm0zi9zi1zi4_DataziByteString_zdwa4_info", referenced from:
>   _Lib_zdwa_info in B.o
>   "_bytestringzm0zi9zi1zi4_DataziByteString_reverse_info", referenced from:
>   _Lib_rev_info in B.o
> ld: symbol(s) not found
> collect2: ld returned 1 exit status
> 
> 
> If I replace ByteString with the ordinary String, the above programs can be
> compiled and linked.
> 
> Can someone tell me what I did wrong here?

Add -package bytestring to the ghc command line options. I believe that
adding --make also may work.

Regards,
-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Convert IO Int to Int

2009-06-09 Thread Jochem Berndsen
ptrash wrote:
> Hi,
> 
> I am using the System.Random method randomRIO. How can I convert its output
> to an Int?
> 
> Thanks...

You cannot [1], you should read up on monads and I/O in Haskell, for example
http://haskell.org/haskellwiki/IO_inside

[1] Yes, you can, but no, you don't want to.

Regards,

-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to compile base?

2009-06-09 Thread Jochem Berndsen
Henk-Jan van Tuyl wrote:
> I tried to compile base-4.0.0.0 (on Windows XP) as follows:
>   [...]\base\4.0.0.0>runhaskell Setup configure
>   : module `Prelude' is not loaded
> It seems that Base needs another way to compile, how?
> 

AFAIK base is shipped with GHC, and cannot be compiled separately.
GHC 6.10.1 ships with base-4.0.0.0, later versions in the 6.10.x series
may have a somewhat later version.

Regards,

-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Problem with Data.Map

2009-06-08 Thread Jochem Berndsen
michael rice wrote:
> I don't understand your response. I copied the imports from Hoogles Data.Map 
> page. What should the imports be?
> 
> Michael

The imports are fine, but instead of 'fromList' you should use
'Map.fromList' or 'Data.Map.fromList'.

Regards,
-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Problem with Data.Map

2009-06-08 Thread Jochem Berndsen
michael rice wrote:
> Gotcha. Thanks!
> 
> Also wondering why I need two imports for one module.

This is not strictly necessary, but the scoping also applies to the type
'Map' itself, thus leaving the
import Data.Map (Map)
(this brings only the name "Map" in scope from module Data.Map) out
would force you to write Data.Map.Map everywhere instead of just 'Map'.

Regards,

-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Problem with Data.Map

2009-06-08 Thread Jochem Berndsen
michael rice wrote:
> I'm trying to understand Map type for possible use in another problem I'm 
> working on, but am stymied right off the bat.
> 
> ==Here's my source:
> 
> import Data.Map (Map)
> import qualified Data.Map as Map
> 
> *Main> fromList $ zip l1 l2
> 
> :1:0: Not in scope: `fromList'

You imported map "qualified as Map", that means that only 'Map.fromList'
and 'Data.Map.fromList' are in scope, and not 'fromList'. The reason one
normally does it like this is that a lot of function names clash with
the Prelude (on purpose). Normally one uses "qualified as M" or
"qualified as Map" to shorten the notation.

HTH,

-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] measure a function in ghci

2009-06-03 Thread Jochem Berndsen
Nico Rolle wrote:
> is there a quick way to check which function is doing the job quicker?
> i have 2 functions which i want to compare.
> both give the same output but they do it in different manner.
> i want to test which one is faster.
> i use ghci.

For simple testing in the interactive environment, use
:set +s
and after each evaluation the memory usage and the number of elapsed
seconds will be displayed.

If you want more, look up the profiling support in the documentation of GHC
http://www.haskell.org/ghc/docs/latest/html/users_guide/profiling.html
GHC provides both memory and time profiling.

Regards,

-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] GSoC update: sneak peek at the live heap profiler

2009-06-03 Thread Jochem Berndsen
Patai Gergely wrote:
> Hello everyone,
> 
> finally there's a bit of eye candy for anyone interested in the heap
> profiling project:
> 
> http://just-bottom.blogspot.com/
> 
> Feel encouraged to comment and check out the project page too, where you
> can already see the beginnings of the core library.

Seems pretty cool :) Will this graph be interactive during the run of
the program?

(I tried to comment on the web page -- however, it didn't let me.
Firefox 3.0 on Debian)

Cheers,

-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Function Returning Type?

2009-05-21 Thread Jochem Berndsen
Jochem Berndsen wrote:
> This makes sense, since "rationals" has type Integer

I meant "Integer -> String" obviously.

Regards,

-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Function Returning Type?

2009-05-21 Thread Jochem Berndsen
jrw4 wrote:
> I wrote this function as I am just learning Haskell.  What it does is it
> generates a list of all rational numbers between 0 and 1, but I only have it
> show the first 20.
> 
> rationals n :: Integer -> String
> rationals n = (putStr . unlines . map show) (take n (nub [x % y | y <-
> [1..], x <- [1..y], x < y]))
> 
> Now my problem is the type declaration, the first line.  I get the error
> "Invalid type signature".  I googled this error and I was not able to find
> out why it is giving it to me.  I have also tried:
> 
> rationals n :: Integer -> [Ratio]
> 
> but it gives me the same error.
> 
> Please someone point me in the right direction.  Thanks.

Just
rationals :: Integer -> String

suffices. (Without the argument 'n'.)

This makes sense, since "rationals" has type Integer. "rationals n" has
type String. (But you still cannot declare that in toplevel that way.)

Regards,

-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ANN: TxtSushi 0.1

2009-05-17 Thread Jochem Berndsen
Keith Sheppard wrote:
> I have released the first version of TxtSushi which is a collection of
> command line utils (written in haskell of course) for processing
> tab-delimited and CSV files. It includes a util for doing SQL SELECTs
> on flat files. This is my first haskell project and feedback of all
> kinds is appreciated.
> 
> Home Page: http://www.keithsheppard.name/txt-sushi
> Darcs Repository: http://patch-tag.com/r/txt-sushi/home
> Issue Tracking: http://code.google.com/p/txt-sushi

Nice! Have you considered putting this on Hackage? That is most useful
for users of your code. I saw you already cabalized the code, so it
should suffice to upload it.

Cheers

-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Data.Map.Map Pattern Matching

2009-05-13 Thread Jochem Berndsen
Nico Rolle wrote:
> Hi
>
> I tried this but it diddn't work in ghci:
>
> import qualified Data.Map as Map
>
> test :: Map.Map [Int] [[Int]] -> Bool
> test (fromList[((i:is), (j:js))]) = [i] == j
>
> i get the : "Parse error in pattern
> Failed." error.

Pattern matching only works on constructors (and view patterns, but they
are a bit more advanced.) I'm not sure what you are trying to
accomplish, could you elaborate?

Cheers,
-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Main function error

2009-05-12 Thread Jochem Berndsen
applebiz89 wrote:
> main :: IO ()
> main = do
>  doFilmsInGivenYear films
>  main

You pass as argument to 'doFilmsInGivenYear' the value 'films', which is
not defined. Instead, I think you meant 'testDatabase'.

All the best,

-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] is value evaluated?

2009-05-07 Thread Jochem Berndsen
Nikhil Patil wrote:
> Hi,
>
> I am curious to know if there is a function in Haskell to find if a
certain
> value has already been evaluated. The function I need would have the type:
>
>> (?!) :: a -> Bool

I will call this function `evaluated', since it is not a binary operator.

The existence of such a function would violate referential transparency.

What would the value of
( evaluated (fibs !! 100), evaluated (fibs !! 100) )
be ? Suppose that I first print the `fst' of this tuple, then print the
101st Fibonacci nummber, and then print the `snd' of this tuple. By lazy
evaluation, one would expect that this yields

False

True

but this violates referential transparency.

Cheers,
-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Not in scope

2009-04-25 Thread Jochem Berndsen
siso dagbovie wrote:
> Hi,
> 
> I've defined the datatype:
> 
> data Graph a b = Empty | Context a b :& Graph a b
> 
> and the function
> 
>  isEmpty :: Graph a b -> Bool
>  isEmpty Empty = True
>  isEmpty _ = False
> 
> and when I do a test run with the graph, 
> ( [ ],2,'c',[("down",3)]) :& Empty
> 
> Haskell is bringing the message "  Not in scope: data constructor `:&' "
> Why is that so?

This works for me. Are the definitions in the same file? Otherwise, you
will need to import your definition.

All the best,
-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


haskell-cafe@haskell.org

2009-04-25 Thread Jochem Berndsen
siso dagbovie wrote:
> I've defined the following datatype with haskell
>
> data Graph a b = Empty | Context a b & Graph a b
>
> But I am having the error message: " parse error on input `&'  ".
> I am wondering what it is wrong with my definition. How can I fix this?

Constructors have to start with a capital or a : (colon).
So changing your definition into
data Graph a b = Empty | Context a b :& Graph a b
will work.

If you want you can define
(&) = (:&)
and use the & symbol for constructing graphs (not in pattern matches
though).

HTH,

-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] want to upgrade to 6.10.1 ghc

2009-03-27 Thread Jochem Berndsen
Vasili I. Galchin wrote:
> I am running Ubuntu Linux. I have forgotten what is the preferred
> means of upgrading. Download the source and compile it using my current
> compiler .. 6.8.2?

I would recommend to download the binary distribution for your
architecture, unpack it and install it.
http://www.haskell.org/ghc

Regards,

-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Link errors

2009-03-15 Thread Jochem Berndsen
Lingappan, Loganathan wrote:
> If I include
> 
> import Text.Regex.Posix ((=~))
> 
> into a Haskell code, I get the following link error:
> 
> FindBBUsage.o:fake:(.text+0x44d): undefined reference to 
> `__stginit_regexzmposixzm0zi72zi0zi3_TextziRegexziPosix_'
> collect2: ld returned 1 exit status
> 
> Any ideas on how to fix this? I am using GHC version 6.10.1 on Windows XP.

Did you use --make ?

Regards,

-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Partial pattern matching

2009-03-09 Thread Jochem Berndsen
Peter Verswyvelen wrote:
> In Haskell, a data constructor can be used partially applied:
> data Pair a b = P a b
>
> f = P 1
>
> however, I cannot do "partial pattern matching", e.g
>
> firstCoord (P x) = x
>
> does not work.
>
> I guess a very important reason must exist why this is the case?
>

What would be the type of firstCoord?


Typically, you'd use

data Pair a b = P { firstCoord :: a
  , secondCoord :: b
  }

or

firstCoord (P x _) = x
secondCoord (P _ y) = y


Regards,

-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] cabal-install 0.6.2 does not bootstrap with ghc-6.10.1 debian distribution

2009-03-08 Thread Jochem Berndsen
Ahn, Ki Yung wrote:
> If anyone who are not using debian distribution ghc-6.10.1 (e.g.,
> general linux binary ghc-6.10.1 or source compiled one) can try
> bootstrapping cabal-install 0.6.2 from scratch also finds the same
> problem, I think someone should make a ticket for cabal-install.

I remember having to install zlib1g-dev using the package manager,

   aptitude install zlib1g-dev

should suffice. If this was not the problem, please post the exact error
message so we can figure out what's going wrong.

Regards,

-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ANN: The Typeclassopedia, and request for feedback

2009-02-16 Thread Jochem Berndsen
Brent Yorgey wrote:
> My hope is that this will be a valuable resource to the Haskell
> community, especially those who are learning.  Any feedback would be
> greatly appreciated, especially if it helps improve the article before
> publication.  A draft can be found here:
>   
> http://www.cis.upenn.edu/~byorgey/papers/typeclassopedia-draft-090216.pdf
> 
> Also see my blog post for a bit more info:
>  
> 
> http://byorgey.wordpress.com/2009/02/16/the-typeclassopedia-request-for-feedback/
> 

This is really great! Thanks for doing this.

Regards,

-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] lazy evaluation is not complete

2009-02-09 Thread Jochem Berndsen
Peter Padawitz wrote:
> A simplied version of Example 5-16 in Manna's classical book
> "Mathematical Theory of Computation":
>
> foo x = if x == 0 then 0 else foo (x-1)*foo (x+1)
>
> If run with ghci, foo 5 does not terminate, i.e., Haskell does not look
> for all outermost redices in parallel. Why? For efficiency reasons?
>
> It's a pity because a parallel-outermost strategy would be complete.

(*) is strict in both arguments for Int. If you want to avoid this, you
could do
newtype X = X Int
and write your own implementation of (*) that is nonstrict.

-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Happstack 0.1 Released!

2009-02-05 Thread Jochem Berndsen
Neil Mitchell wrote:
> Successor as in Happstack replaces HAppS entirely and all projects
> implemented in HAppS should aim to port to Happstack - or successor as
> in builds on the ideas in HAppS? Is HAppS now deprecated?

The HAppS project has been abandoned, see
http://groups.google.com/group/HAppS/msg/d128331e213c1031 .

The Happstack project is intended to continue development. For more
details, see http://happstack.com/faq.html .

-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] ANN: Hasim, discrete event simulation in Haskell

2008-06-30 Thread Jochem Berndsen
Hi all,

I've started a small project to create a library to do discrete event
simulation in Haskell. Its website is located at
http://huygens.functor.nl/hasim . It uses monads to define a
domain-specific language for "actions" of a process. The interested
reader is referred to the website. 

Regards,

-- 
Jochem Berndsen | [EMAIL PROTECTED]
GPG: 0xE6FABFAB


signature.asc
Description: This is a digitally signed message part
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe