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

2007-12-28 Thread Lennart Augustsson
There's no (valid) formalism that says that [n..]==[n..] is True.
The formalism says that [n..] and [n..] are equal.  But being equal does not
mean that the Haskell (==) function returns True.
The (==) function is just an approximation of semantic equality (by
necessity).

  -- Lennart

On Dec 28, 2007 3:38 AM, Albert Y. C. Lai [EMAIL PROTECTED] wrote:

 Achim Schneider wrote:
  [n..] == [m..],
 
  the first thing I notice is
 
  n == m  n+1 == m+1
 
  , which already expresses all of infinity in one instance and can be
  trivially cancelled to
 
  n == m
 
  , which makes the whole darn thing only _|_ if n or m is _|_, which no
  member of [n..] can be as long as n isn't or 1 or + has funny ideas.
 
  I finally begin to understand my love and hate relationship with
  formalisms: It involves cuddling with fixed points while protecting
  them from evil data and fixed points they don't like as well as
  reduction strategies that don't see their full beauty.

 There is a formalism that says [n..]==[n..] is true. (Look for
 co-induction, observational equivalence, bismulation, ...)

 There is a formalism that says [n..]==[n..] is _|_.

 We know of implemented programming languages that can give an answer
 according to the latter formalism.

 If you know of an implemented programming language that can give an
 answer according to the former formalism, and not just for the obvious
 [n..] but also map f xs == map g xs (for example), please spread the news.

 So it comes down to which formalism, not whether formalism.

 I have long known the problem with informalisms. They are full of I
 know, obviously, and ought to be. It is too tempting to take your
 wit for granted. When you make a deduction, you don't easily see whether
 it is one of a systemtic family of deductions or you are just cunning.
 You only see what you can do; you don't see what you can't do, much less
 what you can't make a computer do.

 Formalisms do not tolerate such self-deception. You think something
 ought to be obvious? Write them down as axioms. Now with all your
 obviousness nailed down black on white, you have a solid ground on which
 to ask: what can be done, what can't be done, what can be done on a
 computer, how practical is it? Humility and productivity are thus
 restored.
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

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


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

2007-12-28 Thread Miguel Mitrofanov
 Questions:
 The fact that Haskell functions are monotone continuous functions on  
 pointed complete partial orders imply this ?
 - every domain in Haskell is a pointed complete partial order, including  
 domains of functions ?

Right.

 - the structure of a domain is preserved in the result when you apply a  
 Haskell function to it ?

Right, if your structure means complete partial order. Note that (_|_) (the 
least element in this order) is not necessarily preserved.

 - every domain can be enumerated ?

Ehm... No. Well, it depends on what you mean by enumeration.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2007-12-28 Thread ajb

G'day all.

Quoting Achim Schneider [EMAIL PROTECTED]:


And if it wouldn't? After all, arguing that |N == |N is undefined
because it takes too long to check would earn you a straight F in any
math test.


That's only because you spelled it incorrectly for the purpose of
a maths test.  Had you written this:

\[ (\N =_w \N) = \bot \]

you'd be on firmer ground.

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


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

2007-12-28 Thread Miguel Mitrofanov
 How can I test that partial order in Haskell ?

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

In fact, you only have to worry about non-maximal values when you use 
recursion. The fundamental property of Haskell is that it computes the least 
fixed point. For example, if f maps (_|_) to (_|_), then let x = f x in x 
will evaluate to (_|_) - and you loop forever, see above.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2007-12-28 Thread Cristian Baboi

Thank you.

It sounds like a limit. xn -- x for n --  :-)

How can I get that maximal value when I start from a non maximal one ?

[1 .. ] and x=1:x are maximal ?


On Fri, 28 Dec 2007 11:21:36 +0200, Miguel Mitrofanov  
[EMAIL PROTECTED] wrote:



How can I test that partial order in Haskell ?


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


In fact, you only have to worry about non-maximal values when you use  
recursion. The fundamental property of Haskell is that it computes the  
least fixed point. For example, if f maps (_|_) to (_|_), then let x =  
f x in x will evaluate to (_|_) - and you loop forever, see above.




 Information from NOD32 
This message was checked by NOD32 Antivirus System for Linux Mail Servers.
 part000.txt - is OK
http://www.eset.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2007-12-28 Thread Peter Gammie

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


How can I test that partial order in Haskell ?


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


Right, so when I say to GHCi:

Prelude take 5 [1..]

and it says:

[1,2,3,4,5]

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


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


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


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


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

2007-12-28 Thread Miguel Mitrofanov
 It sounds like a limit. xn -- x for n --  :-)

Yeah, that's right.

 How can I get that maximal value when I start from a non maximal one ?

Not a problem. For example, const 1 maps each value (even (_|_)) to the 
maximal value 1.

 [1 .. ] and x=1:x are maximal ?

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


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

2007-12-28 Thread Cristian Baboi
On Fri, 28 Dec 2007 12:01:51 +0200, Miguel Mitrofanov  
[EMAIL PROTECTED] wrote:



It sounds like a limit. xn -- x for n --  :-)


Yeah, that's right.


If xn is monotone, then I only have to worry when it is not bounded, right  
?



How can I get that maximal value when I start from a non maximal one ?


Not a problem. For example, const 1 maps each value (even (_|_)) to  
the maximal value 1.



[1 .. ] and x=1:x are maximal ?


Can you give me some examples of non maximal ones ?



 Information from NOD32 
This message was checked by NOD32 Antivirus System for Linux Mail Servers.
 part000.txt - is OK
http://www.eset.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2007-12-28 Thread Cristian Baboi

Thank you.

This is what I understand so far:

- the maximal values is what is usually called data
- the non maximal are what is usually   called code
- in functional languages one can be given non maximal values (code) as  
input


Is that right ?


On Fri, 28 Dec 2007 12:01:51 +0200, Miguel Mitrofanov  
[EMAIL PROTECTED] wrote:



It sounds like a limit. xn -- x for n --  :-)


Yeah, that's right.


How can I get that maximal value when I start from a non maximal one ?


Not a problem. For example, const 1 maps each value (even (_|_)) to  
the maximal value 1.



[1 .. ] and x=1:x are maximal ?


Yes.




 Information from NOD32 
This message was checked by NOD32 Antivirus System for Linux Mail Servers.
 part000.txt - is OK
http://www.eset.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2007-12-28 Thread Cristian Baboi
On Fri, 28 Dec 2007 12:01:51 +0200, Miguel Mitrofanov  
[EMAIL PROTECTED] wrote:




[1 .. ] and x=1:x are maximal ?


Yes.



How can a Haskell implementation recognize a maximal value ?

x=1:x for example.



 Information from NOD32 
This message was checked by NOD32 Antivirus System for Linux Mail Servers.
 part000.txt - is OK
http://www.eset.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2007-12-28 Thread Miguel Mitrofanov
 Right, so when I say to GHCi:
 Prelude take 5 [1..]
 and it says:
 [1,2,3,4,5]
 then it really has computed the entirety of the infinite sequence  
 [1..], and not some approximation?

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

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

Well, that depends of your notion of interesting.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2007-12-28 Thread apfelmus

Cristian Baboi wrote:

 http://en.wikipedia.org/wiki/First-class_object

The term was coined by Christopher Strachey in the context of “functions 
as first-class citizens” in the mid-1960's.[1]


Depending on the language, this can imply:
1.  being expressible as an anonymous literal value
2.  being storable in variables
3.  being storable in data structures
4.  having an intrinsic identity (independent of any given name)
5.  being comparable for equality with other entities
6.  being passable as a parameter to a procedure/function
7.  being returnable as the result of a procedure/function
8.  being constructable at runtime
9.  being printable
10. being readable
11. being transmissible among distributed processes
12. being storable outside running processes

I'll guess that 5,9,12 does not apply to Haskell functions.


Exactly, together with 10 and 11 (when the distributed processes are on 
different machines).


But there is good reason that those things can't be done in Haskell. 
With extensional equality (two functions are considered equal if they 
yield the same result on every possible argument) number 5 is 
undecidable. Similarly, there cannot be functions


  print   :: (Int - Int) - String
  compile :: String - (Int - Int)

with

  compile . print = id

A  print  function based on an intensional representation (assembly, 
byte code, etc.) would have to distinguish extensionally equal functions


  print f ≠ print g   although   f = g

which is not allowed.


More importantly, I don't quite understand your question. If you 
definitively need 9-12 for a practical problem at hand, then you may 
want to take a look at the functional language Clean


  http://clean.cs.ru.nl/

which is similar to Haskell but offers 9-12 in some form.

In all other cases, an email thread is not a good (often not even 
successful) way to get a coherent world view on Haskell (or on 
something  else) since this necessarily involves nitpicking 
philosophical questions. In my experience, interrogating one person in 
real-time in audio and interrogating books are the best ways to do 
that. Concerning books, maybe


  The Haskell Road to Logic, Maths and Programming
  http://www.cwi.nl/~jve/HR

is for you. More books on

  http://haskell.org/haskellwiki/Books

You don't have to buy them, borrow them from a library.


Regards,
apfelmus

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


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

2007-12-28 Thread Miguel Mitrofanov
  It sounds like a limit. xn -- x for n --  :-)
 
  Yeah, that's right.
 If xn is monotone, then I only have to worry when it is not bounded, right  
 ?

Sorry, don't understand what you mean. Yes, the monotone sequence has a limit. 
No, it's not necessarily maximal.

  [1 .. ] and x=1:x are maximal ?
 Can you give me some examples of non maximal ones ?

let x = x+1 in x

Or even

let x = x in x

In both cases, (_|_) is the least fixed point, and is non-maximal.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Doing some things right

2007-12-28 Thread Andrew Coppin

Don Stewart wrote:

A Wake Up Call for the Logic Programming Community

Or what the logic programming community can learn from the Haskell
community (in particular):


http://www.cs.kuleuven.ac.be/%7Edtai/projects/ALP//newsletter/dec07/content/Articles/tom/content.html

Interesting read!
  


Haskell is the undisputed flagship of the FP community.

Er... really? I thought Lisp and Erlang were both infinitely more 
popular and better known. Followed by Clean and O'Camal. Indeed, until I 
stumbled across an article on Wikipidia quite by chance, I'd never even 
*heard* of this thing called Haskell. (Note to self: Add more links to 
the Haskell page on Wikipedia...)


[I actually heard a number of people tell me that learning LISP would 
change my life forever because LISP has something called macros. I 
tried to learn it, and disliked it greatly. It's too messy. And what the 
heck is cdr ment to mean anyway? To me, LISP doesn't even seem all 
that different from normal languages (modulo weird syntax). Now 
Haskell... that's FUN!]



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


[Haskell-cafe] what does @ mean?.....

2007-12-28 Thread Nicholls, Mark
Hello, I wonder if someone could answer the following...

The short question is what does @ mean in 

 

mulNat a b

| a = b = mulNat' a b b

| otherwise = mulNat' b a a

where

 mulNat' x@(S a) y orig

 | x == one = y

 | otherwise = mulNat' a (addNat orig y) orig

 

The long version, explaining what everything means is

 

 here's a definition of multiplication on natural numbers I'm reading

 on a blog

 

 data Nat = Z | S Nat

deriving Show

 

 one :: Nat

 one = (S Z)

 

 mulNat :: Nat - Nat - Nat

 mulNat _ Z = Z

 mulNat Z _ = Z

 mulNat a b

| a = b = mulNat' a b b

| otherwise = mulNat' b a a

where

 mulNat' x@(S a) y orig

 | x == one = y

 | otherwise = mulNat' a (addNat orig y) orig

 

 Haskell programmers seem to have a very irritating habit of trying to

 be overly concise...which makes learnign the language extremely

 hard...this example is actually relatively verbosebut anyway...

 

 Z looks like Zero...S is the successor function...Nat are the

 Natural numbers.

 

 mulNat _ Z = Z

 mulNat Z _ = Z

 

 translates to...

 

 x * 0 = 0fine...

 0 * x = 0fine..

 

 mulNat a b

| a = b = mulNat' a b b

| otherwise = mulNat' b a a

where

 mulNat' x@(S a) y orig

 | x == one = y

 | otherwise = mulNat' a (addNat orig y) orig

 

 is a bit more problematic...

 lets take a as 3 and b as 5...

 

 so now we have

 

 mulNat' 3 5 5

 

 but what does the x@(S a) mean? in

 

 mulNat' x@(S a) y orig

 



From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Nicholls, Mark
Sent: 21 December 2007 17:47
To: David Menendez
Cc: Jules Bean; haskell-cafe@haskell.org
Subject: RE: [Haskell-cafe] nice simple problem for someone
struggling

 

Let me resend the code...as it stands

 

module Main where

 

data SquareType numberType = Num numberType = SquareConstructor
numberType

 

class ShapeInterface shape where

  area :: Num numberType = shape-numberType

 

data ShapeType = forall a. ShapeInterface a = ShapeType a

 

instance (Num a) = ShapeInterface (SquareType a) where 

area (SquareConstructor side) = side * side

 

 

and the errors are for the instance declaration...

 

[1 of 1] Compiling Main ( Main.hs, C:\Documents and
Settings\nichom\Haskell\Shapes2\out/Main.o )

 

Main.hs:71:36:

Couldn't match expected type `numberType' against inferred type `a'

  `numberType' is a rigid type variable bound by

   the type signature for `area' at Main.hs:38:15

  `a' is a rigid type variable bound by

  the instance declaration at Main.hs:70:14

In the expression: side * side

In the definition of `area':

area (SquareConstructor side) = side * side

 

I'm becoming lost in errors I don't comprehend

 

What bamboozles me is it seemed such a minor enhancement.



From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of David Menendez
Sent: 21 December 2007 17:05
To: Nicholls, Mark
Cc: Jules Bean; haskell-cafe@haskell.org
Subject: Re: [Haskell-cafe] nice simple problem for someone
struggling

 

On Dec 21, 2007 11:50 AM, Nicholls, Mark [EMAIL PROTECTED]
wrote:

Now I have

module Main where

data SquareType numberType = Num numberType = SquareConstructor
numberType


This is a valid declaration, but I don't think it does what you want it
to. The constraint on numberType applies only to the data constructor. 

That is, given an unknown value of type SquareType a for some a, we do
not have enough information to infer Num a.

For your code, you want something like:

instance (Num a) = ShapeInterface (SquareType a) where 
area (SquareConstructor side) = side * side


-- 
Dave Menendez [EMAIL PROTECTED]
http://www.eyrie.org/~zednenem/  

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


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

2007-12-28 Thread Peter Gammie

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


Right, so when I say to GHCi:



Prelude take 5 [1..]



and it says:



[1,2,3,4,5]



then it really has computed the entirety of the infinite sequence



[1..], and not some approximation?



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


I'll bite. So what do you expect:

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

to do? How about:

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

?

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


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


Well, that depends of your notion of interesting.


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


cheers
peter

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


Re: [Haskell-cafe] what does @ mean?.....

2007-12-28 Thread Alfonso Acosta
@ works as an aliasing primitive for the arguments of a function

f x@(Just y) = ...

using x in the body of f is equivalent to use Just y. Perhaps in
this case is not really useful, but in some other cases it saves the
effort and space of retyping really long expressions. And what is even
more important, in case an error is made when choosing the pattern,
you only have to correct it in one place.

On Dec 28, 2007 12:05 PM, Nicholls, Mark [EMAIL PROTECTED] wrote:




 Hello, I wonder if someone could answer the following…

 The short question is what does @ mean in



 mulNat a b

 | a = b = mulNat' a b b

 | otherwise = mulNat' b a a

 where

  mulNat' x@(S a) y orig

  | x == one = y

  | otherwise = mulNat' a (addNat orig y) orig



 The long version, explaining what everything means is….



  here's a definition of multiplication on natural numbers I'm reading

  on a blog



  data Nat = Z | S Nat

 deriving Show



  one :: Nat

  one = (S Z)



  mulNat :: Nat - Nat - Nat

  mulNat _ Z = Z

  mulNat Z _ = Z

  mulNat a b

 | a = b = mulNat' a b b

 | otherwise = mulNat' b a a

 where

  mulNat' x@(S a) y orig

  | x == one = y

  | otherwise = mulNat' a (addNat orig y) orig



  Haskell programmers seem to have a very irritating habit of trying to

  be overly concise...which makes learnign the language extremely

  hard...this example is actually relatively verbosebut anyway...



  Z looks like Zero...S is the successor function...Nat are the

  Natural numbers.



  mulNat _ Z = Z

  mulNat Z _ = Z



  translates to...



  x * 0 = 0fine...

  0 * x = 0fine..



  mulNat a b

 | a = b = mulNat' a b b

 | otherwise = mulNat' b a a

 where

  mulNat' x@(S a) y orig

  | x == one = y

  | otherwise = mulNat' a (addNat orig y) orig



  is a bit more problematic...

  lets take a as 3 and b as 5...



  so now we have



  mulNat' 3 5 5



  but what does the x@(S a) mean? in



  mulNat' x@(S a) y orig



  


 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] On Behalf Of Nicholls, Mark
  Sent: 21 December 2007 17:47
  To: David Menendez
  Cc: Jules Bean; haskell-cafe@haskell.org
  Subject: RE: [Haskell-cafe] nice simple problem for someone struggling



 Let me resend the code…as it stands….



 module Main where



 data SquareType numberType = Num numberType = SquareConstructor numberType



 class ShapeInterface shape where

   area :: Num numberType = shape-numberType



 data ShapeType = forall a. ShapeInterface a = ShapeType a



 instance (Num a) = ShapeInterface (SquareType a) where

 area (SquareConstructor side) = side * side





 and the errors are for the instance declaration…….



 [1 of 1] Compiling Main ( Main.hs, C:\Documents and
 Settings\nichom\Haskell\Shapes2\out/Main.o )



 Main.hs:71:36:

 Couldn't match expected type `numberType' against inferred type `a'

   `numberType' is a rigid type variable bound by

the type signature for `area' at Main.hs:38:15

   `a' is a rigid type variable bound by

   the instance declaration at Main.hs:70:14

 In the expression: side * side

 In the definition of `area':

 area (SquareConstructor side) = side * side



 I'm becoming lost in errors I don't comprehend….



 What bamboozles me is it seemed such a minor enhancement.


  


 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of
 David Menendez
  Sent: 21 December 2007 17:05
  To: Nicholls, Mark
  Cc: Jules Bean; haskell-cafe@haskell.org
  Subject: Re: [Haskell-cafe] nice simple problem for someone struggling



 On Dec 21, 2007 11:50 AM, Nicholls, Mark [EMAIL PROTECTED] wrote:



 Now I have

  module Main where

  data SquareType numberType = Num numberType = SquareConstructor
  numberType



  This is a valid declaration, but I don't think it does what you want it to.
 The constraint on numberType applies only to the data constructor.

  That is, given an unknown value of type SquareType a for some a, we do not
 have enough information to infer Num a.

  For your code, you want something like:

  instance (Num a) = ShapeInterface (SquareType a) where
  area (SquareConstructor side) = side * side


  --
  Dave Menendez [EMAIL PROTECTED]
  http://www.eyrie.org/~zednenem/ 
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


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


RE: [Haskell-cafe] what does @ mean?.....

2007-12-28 Thread Nicholls, Mark
So in the example given...

mulNat a b
 | a = b = mulNat' a b b
 | otherwise = mulNat' b a a
 where
  mulNat' x@(S a) y orig
  | x == one = y
  | otherwise = mulNat' a (addNat orig y) orig

Is equivalent to 

mulNat a b
 | a = b = mulNat' a b b
 | otherwise = mulNat' b a a
 where
  mulNat' (S a) y orig
  | (S a) == one = y
  | otherwise = mulNat' a (addNat orig y) orig

?

-Original Message-
From: Alfonso Acosta [mailto:[EMAIL PROTECTED] 
Sent: 28 December 2007 11:20
To: Nicholls, Mark
Cc: haskell-cafe@haskell.org
Subject: Re: [Haskell-cafe] what does @ mean?.

@ works as an aliasing primitive for the arguments of a function

f x@(Just y) = ...

using x in the body of f is equivalent to use Just y. Perhaps in
this case is not really useful, but in some other cases it saves the
effort and space of retyping really long expressions. And what is even
more important, in case an error is made when choosing the pattern,
you only have to correct it in one place.

On Dec 28, 2007 12:05 PM, Nicholls, Mark [EMAIL PROTECTED]
wrote:




 Hello, I wonder if someone could answer the following...

 The short question is what does @ mean in



 mulNat a b

 | a = b = mulNat' a b b

 | otherwise = mulNat' b a a

 where

  mulNat' x@(S a) y orig

  | x == one = y

  | otherwise = mulNat' a (addNat orig y) orig



 The long version, explaining what everything means is



  here's a definition of multiplication on natural numbers I'm reading

  on a blog



  data Nat = Z | S Nat

 deriving Show



  one :: Nat

  one = (S Z)



  mulNat :: Nat - Nat - Nat

  mulNat _ Z = Z

  mulNat Z _ = Z

  mulNat a b

 | a = b = mulNat' a b b

 | otherwise = mulNat' b a a

 where

  mulNat' x@(S a) y orig

  | x == one = y

  | otherwise = mulNat' a (addNat orig y) orig



  Haskell programmers seem to have a very irritating habit of trying to

  be overly concise...which makes learnign the language extremely

  hard...this example is actually relatively verbosebut anyway...



  Z looks like Zero...S is the successor function...Nat are the

  Natural numbers.



  mulNat _ Z = Z

  mulNat Z _ = Z



  translates to...



  x * 0 = 0fine...

  0 * x = 0fine..



  mulNat a b

 | a = b = mulNat' a b b

 | otherwise = mulNat' b a a

 where

  mulNat' x@(S a) y orig

  | x == one = y

  | otherwise = mulNat' a (addNat orig y) orig



  is a bit more problematic...

  lets take a as 3 and b as 5...



  so now we have



  mulNat' 3 5 5



  but what does the x@(S a) mean? in



  mulNat' x@(S a) y orig



  


 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] On Behalf Of Nicholls, Mark
  Sent: 21 December 2007 17:47
  To: David Menendez
  Cc: Jules Bean; haskell-cafe@haskell.org
  Subject: RE: [Haskell-cafe] nice simple problem for someone
struggling



 Let me resend the code...as it stands



 module Main where



 data SquareType numberType = Num numberType = SquareConstructor
numberType



 class ShapeInterface shape where

   area :: Num numberType = shape-numberType



 data ShapeType = forall a. ShapeInterface a = ShapeType a



 instance (Num a) = ShapeInterface (SquareType a) where

 area (SquareConstructor side) = side * side





 and the errors are for the instance declaration...



 [1 of 1] Compiling Main ( Main.hs, C:\Documents and
 Settings\nichom\Haskell\Shapes2\out/Main.o )



 Main.hs:71:36:

 Couldn't match expected type `numberType' against inferred type
`a'

   `numberType' is a rigid type variable bound by

the type signature for `area' at Main.hs:38:15

   `a' is a rigid type variable bound by

   the instance declaration at Main.hs:70:14

 In the expression: side * side

 In the definition of `area':

 area (SquareConstructor side) = side * side



 I'm becoming lost in errors I don't comprehend



 What bamboozles me is it seemed such a minor enhancement.


  


 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of
 David Menendez
  Sent: 21 December 2007 17:05
  To: Nicholls, Mark
  Cc: Jules Bean; haskell-cafe@haskell.org
  Subject: Re: [Haskell-cafe] nice simple problem for someone
struggling



 On Dec 21, 2007 11:50 AM, Nicholls, Mark [EMAIL PROTECTED]
wrote:



 Now I have

  module Main where

  data SquareType numberType = Num numberType = SquareConstructor
  numberType



  This is a valid declaration, but I don't think it does what you want
it to.
 The constraint on numberType applies only to the data constructor.

  That is, given an unknown value of type SquareType a for some a, we
do not
 have enough information to infer Num a.

  For 

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

2007-12-28 Thread Jules Bean

Peter Gammie wrote:

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


Right, so when I say to GHCi:



Prelude take 5 [1..]



and it says:



[1,2,3,4,5]



then it really has computed the entirety of the infinite sequence



[1..], and not some approximation?



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


I'll bite. So what do you expect:

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

to do? How about:

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

?

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


take evaluates as much as it needs of the spine but not any of the elements.

Even then, take is a good producer, so

take 1 . take 5 $ 1:2:3:4:undefined

will converge.

But I think you know all this and your questions are rhetorical :)

Jules


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


Re: [Haskell-cafe] what does @ mean?.....

2007-12-28 Thread Chaddaï Fouché
2007/12/28, Alfonso Acosta [EMAIL PROTECTED]:
 @ works as an aliasing primitive for the arguments of a function

 f x@(Just y) = ...

 using x in the body of f is equivalent to use Just y. Perhaps in
 this case is not really useful, but in some other cases it saves the
 effort and space of retyping really long expressions. And what is even
 more important, in case an error is made when choosing the pattern,
 you only have to correct it in one place.


And in plenty of case it will greatly boost your speed because you
won't be reconstructing the objects against which you matched every
time you want to return them unchanged.

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


Re: [Haskell-cafe] what does @ mean?.....

2007-12-28 Thread Chaddaï Fouché
2007/12/28, Nicholls, Mark [EMAIL PROTECTED]:
 So in the example given...

 mulNat a b
  | a = b = mulNat' a b b
  | otherwise = mulNat' b a a
  where
   mulNat' x@(S a) y orig
   | x == one = y
   | otherwise = mulNat' a (addNat orig y) orig

 Is equivalent to

 mulNat a b
  | a = b = mulNat' a b b
  | otherwise = mulNat' b a a
  where
   mulNat' (S a) y orig
   | (S a) == one = y
   | otherwise = mulNat' a (addNat orig y) orig

 ?

Yes, but in the second version, it has to reconstruct (S a) before
comparing it to one where in the first it could do the comparison
directly. In this cas there may be some optimisation involved that
negate this difference but in many case it can do a real performance
difference.
The as-pattern (@ means as) is both practical and performant in most cases.

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


RE: [Haskell-cafe] what does @ mean?.....

2007-12-28 Thread Nicholls, Mark
Lovelythank you very muchanother small step forward.

-Original Message-
From: Chaddaï Fouché [mailto:[EMAIL PROTECTED] 
Sent: 28 December 2007 11:29
To: Nicholls, Mark
Cc: Alfonso Acosta; haskell-cafe@haskell.org
Subject: Re: [Haskell-cafe] what does @ mean?.

2007/12/28, Nicholls, Mark [EMAIL PROTECTED]:
 So in the example given...

 mulNat a b
  | a = b = mulNat' a b b
  | otherwise = mulNat' b a a
  where
   mulNat' x@(S a) y orig
   | x == one = y
   | otherwise = mulNat' a (addNat orig y) orig

 Is equivalent to

 mulNat a b
  | a = b = mulNat' a b b
  | otherwise = mulNat' b a a
  where
   mulNat' (S a) y orig
   | (S a) == one = y
   | otherwise = mulNat' a (addNat orig y) orig

 ?

Yes, but in the second version, it has to reconstruct (S a) before
comparing it to one where in the first it could do the comparison
directly. In this cas there may be some optimisation involved that
negate this difference but in many case it can do a real performance
difference.
The as-pattern (@ means as) is both practical and performant in most cases.

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


[Haskell-cafe] Missing join and split

2007-12-28 Thread Mitar
Hi!

I am really missing the (general) split function built in standard
Haskell. I do not understand why there is something so specific as
words and lines but not a simple split? The same goes for join.

Yes, I can of course define them but ... in an interactive mode it
would be quite handy to have them there.

Or am I wrong and are those hidden somewhere?

So what are common ways to get around this? What are elegant
definitions? Inline definitions?


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


Re: [Haskell-cafe] Missing join and split

2007-12-28 Thread Andrew Coppin

Mitar wrote:

Hi!

I am really missing the (general) split function built in standard
Haskell. I do not understand why there is something so specific as
words and lines but not a simple split? The same goes for join.

Yes, I can of course define them but ... in an interactive mode it
would be quite handy to have them there.

Or am I wrong and are those hidden somewhere?

So what are common ways to get around this? What are elegant
definitions? Inline definitions?
  


As I understand it, they don't exist because nobody can agree on the 
best way to define them.


For joining you probably want some combination of intersperse and 
concat, e.g.


 unlines = concat . intersperse \n

For splitting, do we split on a given character? A predicate? Do we keep 
the splitting character or throw it away? Do we generate empty sublists 
or elide them? Apparently nobody can agree on these points, and writing 
a function with all possible options would be very messy...


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


[Haskell-cafe] Re: what does @ mean?.....

2007-12-28 Thread ChrisK
Nicholls, Mark wrote:
 Hello, I wonder if someone could answer the following…
 
 The short question is what does @ mean in
 
  
 
 mulNat a b
 
 | a = b = mulNat' a b b
 
 | otherwise = mulNat' b a a
 
 where
 
  mulNat' x@(S a) y orig
 
  | x == one = y
 
  | otherwise = mulNat' a (addNat orig y) orig
 

The @ means an as-pattern as defined in the Haskell 98 report section 3.17.1
http://www.haskell.org/onlinereport/exps.html#3.17.1

The 'x' binds to the whole (S a) and the 'a' binds to the parameter of the
constructor 's'.

There is a possible performance benefit here.  Consider:

zeroNothing Nothing = Nothing
zeroNothing (Just n) =
  if n == 0 then Nothing else (Just n)

versus

zeroNothing Nothing = Nothing
zeroNothing x@(Just n) =
  if n == 0 then Nothing else x


The first example takes apart the (Just n) and later reconstructs (Just n).
Unless the compiler is fairly clever, this will cause the new (Just n) to be a
new allocation instead of reusing the input value.  The second form uses an
at-pattern to bind 'x' to the whole input parameter and the returned 'x' will
not need to be reallocaed.

-- 
Chris

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


Re: [Haskell-cafe] what does @ mean?.....

2007-12-28 Thread Alfonso Acosta
On Dec 28, 2007 12:21 PM, Nicholls, Mark [EMAIL PROTECTED] wrote:
 So in the example given...

 Is equivalent ?

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


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

2007-12-28 Thread Cristian Baboi
On Fri, 28 Dec 2007 12:03:04 +0200, apfelmus [EMAIL PROTECTED]  
wrote:



Cristian Baboi wrote:

 http://en.wikipedia.org/wiki/First-class_object
 The term was coined by Christopher Strachey in the context of  
“functions as first-class citizens” in the mid-1960's.[1]

 Depending on the language, this can imply:
1.  being expressible as an anonymous literal value
2.  being storable in variables
3.  being storable in data structures
4.  having an intrinsic identity (independent of any given name)
5.  being comparable for equality with other entities
6.  being passable as a parameter to a procedure/function
7.  being returnable as the result of a procedure/function
8.  being constructable at runtime
9.  being printable
10. being readable
11. being transmissible among distributed processes
12. being storable outside running processes
 I'll guess that 5,9,12 does not apply to Haskell functions.


Exactly, together with 10 and 11 (when the distributed processes are on  
different machines).


But there is good reason that those things can't be done in Haskell.  
With extensional equality (two functions are considered equal if they  
yield the same result on every possible argument) number 5 is  
undecidable.


I didn't know 5 as a number is undecidable :-)


Similarly, there cannot be functions



   print   :: (Int - Int) - String
   compile :: String - (Int - Int)

with

   compile . print = id


A  print  function based on an intensional representation (assembly,  
byte code, etc.) would have to distinguish extensionally equal functions



   print f ≠ print g   although   f = g



which is not allowed.


Ok. I understand that there cannot be pairs like (print,compile) above.
But I was told that compile (quality number 10), can be defined.

About print above, I do not intend to make a Haskell String from a Haskell  
function.

This is why I said something about mixing levels of abstractions.

More importantly, I don't quite understand your question. If you  
definitively need 9-12 for a practical problem at hand, then you may  
want to take a look at the functional language Clean


   http://clean.cs.ru.nl/

which is similar to Haskell but offers 9-12 in some form.


How can be Clean similar to Haskell and at the same time satisfy 9-12 ?
I tryed Clean. I like it very much.

I have some silly little problems with it:
- its only 32 bit
- it doesn't support Unicode
- I don't like those type adnotations. Look as ugly as Lisp () to me.
- it's not free
- the linux version seems abandoned.
- there are some issues with # expressions (let before) that I don't fully  
understand

- the IO seems easyer in Haskell than in Clean

Otherwise I like it better than Haskell.


In all other cases, an email thread is not a good (often not even  
successful) way to get a coherent world view on Haskell (or on  
something  else) since this necessarily involves nitpicking  
philosophical questions. In my experience, interrogating one person in  
real-time in audio and interrogating books are the best ways to do  
that.


In my experience, different people have different world views, and one  
cannot get that from books only.




Concerning books, maybe



   The Haskell Road to Logic, Maths and Programming
   http://www.cwi.nl/~jve/HR



is for you.


Thank you.


More books on



   http://haskell.org/haskellwiki/Books



You don't have to buy them, borrow them from a library.


I'l try borrow them when I'll be visiting Munich next year, but I don't  
think I'll have enough time to read them.




 Information from NOD32 
This message was checked by NOD32 Antivirus System for Linux Mail Servers.
 part000.txt - is OK
http://www.eset.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2007-12-28 Thread Peter Gammie

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


So what do you expect:



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



to do?


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


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

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


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


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


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


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

2007-12-28 Thread Miguel Mitrofanov
 I'll bite.

Please, don't.

 So what do you expect:
 take 5 [1,2,3,4,5,undefined]
 to do?

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

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

No, it's implementation details. I'm reasoning about values, not computations, 
and I use complete orders for reasoning. What really matters is that 
implementation gives me results that agree with this reasoning - until we 
consider performance issues.

  Well, that depends of your notion of interesting.
 I defined it - I'm interested in things that are observationally  
 equivalent.

That's your choice, and I certainly can't argue, but I can't help mentioning 
that this is a bit weird.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2007-12-28 Thread Cristian Baboi

Here is how I want print to be in Haskell

print :: (a-b) - (a-b)

with print = id, but the following side effect:

- I want to call the print function today, and get the value tomorrow.



On Fri, 28 Dec 2007 12:03:04 +0200, apfelmus [EMAIL PROTECTED]  
wrote:



Cristian Baboi wrote:

 http://en.wikipedia.org/wiki/First-class_object
 The term was coined by Christopher Strachey in the context of  
“functions as first-class citizens” in the mid-1960's.[1]

 Depending on the language, this can imply:
1.  being expressible as an anonymous literal value
2.  being storable in variables
3.  being storable in data structures
4.  having an intrinsic identity (independent of any given name)
5.  being comparable for equality with other entities
6.  being passable as a parameter to a procedure/function
7.  being returnable as the result of a procedure/function
8.  being constructable at runtime
9.  being printable
10. being readable
11. being transmissible among distributed processes
12. being storable outside running processes
 I'll guess that 5,9,12 does not apply to Haskell functions.


Exactly, together with 10 and 11 (when the distributed processes are on  
different machines).


But there is good reason that those things can't be done in Haskell.  
With extensional equality (two functions are considered equal if they  
yield the same result on every possible argument) number 5 is  
undecidable. Similarly, there cannot be functions


   print   :: (Int - Int) - String
   compile :: String - (Int - Int)

with

   compile . print = id

A  print  function based on an intensional representation (assembly,  
byte code, etc.) would have to distinguish extensionally equal functions


   print f ≠ print g   although   f = g

which is not allowed.



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


 Information from NOD32 
This message was checked by NOD32 Antivirus System for Linux Mail  
Servers.

  part000.txt - is OK
http://www.eset.com





 Information from NOD32 
This message was checked by NOD32 Antivirus System for Linux Mail Servers.
 part000.txt - is OK
http://www.eset.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2007-12-28 Thread Cristian Baboi
But I guess it won't work because the compiler will optimize it and the  
call will disappear.



On Fri, 28 Dec 2007 14:58:53 +0200, Cristian Baboi [EMAIL PROTECTED]  
wrote:



Here is how I want print to be in Haskell

print :: (a-b) - (a-b)

with print = id, but the following side effect:

- I want to call the print function today, and get the value tomorrow.





 Information from NOD32 
This message was checked by NOD32 Antivirus System for Linux Mail Servers.
 part000.txt - is OK
http://www.eset.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2007-12-28 Thread Miguel Mitrofanov
  take 5 [1,2,3,4,5,undefined]
 (What would GHCi print?

[1,2,3,4,5]

 Then please square that with your comment that we don't care how much of  
 the list gets evaluated.)

I don't care if it evaluates it, reads it's answer from some internal table, or 
consult it's lawyer. I just want it to agree with my reasoning about complete 
partial orders; that's all I need. I don't know how to explain this clearer.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2007-12-28 Thread Cristian Baboi
On Fri, 28 Dec 2007 15:29:00 +0200, Miguel Mitrofanov  
[EMAIL PROTECTED] wrote:



 take 5 [1,2,3,4,5,undefined]
(What would GHCi print?


[1,2,3,4,5]


Then please square that with your comment that we don't care how much of
the list gets evaluated.)


I don't care if it evaluates it, reads it's answer from some internal  
table, or consult it's lawyer. I just want it to agree with my reasoning  
about complete partial orders; that's all I need. I don't know how to  
explain this clearer.


This purity of Haskell will allways interfere with practical matters that  
cannot be described in Haskell.






 Information from NOD32 
This message was checked by NOD32 Antivirus System for Linux Mail Servers.
 part000.txt - is OK
http://www.eset.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: what does @ mean?.....

2007-12-28 Thread Achim Schneider
ChrisK [EMAIL PROTECTED] wrote:

 zeroNothing Nothing = Nothing
 zeroNothing (Just n) =
   if n == 0 then Nothing else (Just n)
 
 versus
 
 zeroNothing Nothing = Nothing
 zeroNothing x@(Just n) =
   if n == 0 then Nothing else x
 
versus

zeroNothing Nothing = Nothing
zeroNothing x =
let (Just n) = x
in if n == 0 then Nothing else x

so, @ is kind of like a let, just with its arguments flipped.



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


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

2007-12-28 Thread Jules Bean

It won't work because haskell functions can't have side-effects.

I'm not quite sure what you're trying to say here.

Jules


Cristian Baboi wrote:
But I guess it won't work because the compiler will optimize it and the 
call will disappear.



On Fri, 28 Dec 2007 14:58:53 +0200, Cristian Baboi [EMAIL PROTECTED] 
wrote:



Here is how I want print to be in Haskell

print :: (a-b) - (a-b)

with print = id, but the following side effect:

- I want to call the print function today, and get the value tomorrow.





 Information from NOD32 
This message was checked by NOD32 Antivirus System for Linux Mail Servers.
 part000.txt - is OK
http://www.eset.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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


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

2007-12-28 Thread Cristian Baboi
On Fri, 28 Dec 2007 16:10:15 +0200, Jules Bean [EMAIL PROTECTED]  
wrote:



It won't work because haskell functions can't have side-effects.

I'm not quite sure what you're trying to say here.

Jules



What I am trying to say is:
- storing something to disk does not mean one must have a function to  
convert that something to a Haskell String
- I want to be able to use a function defined in one process in other  
process even if the two does not run at the same time




Cristian Baboi wrote:
But I guess it won't work because the compiler will optimize it and the  
call will disappear.
  On Fri, 28 Dec 2007 14:58:53 +0200, Cristian Baboi  
[EMAIL PROTECTED] wrote:



Here is how I want print to be in Haskell

print :: (a-b) - (a-b)

with print = id, but the following side effect:

- I want to call the print function today, and get the value tomorrow.



   Information from NOD32 
This message was checked by NOD32 Antivirus System for Linux Mail  
Servers.

 part000.txt - is OK
http://www.eset.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe




 Information from NOD32 
This message was checked by NOD32 Antivirus System for Linux Mail  
Servers.

  part000.txt - is OK
http://www.eset.com





 Information from NOD32 
This message was checked by NOD32 Antivirus System for Linux Mail Servers.
 part000.txt - is OK
http://www.eset.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2007-12-28 Thread apfelmus

Jules Bean wrote:

Cristian Baboi wrote:

But I guess it won't work because the compiler will optimize it
and the call will disappear.


I'm not quite sure what you're trying to say here.


(That's the world view on Haskell issue I mean. I know this feeling 
with physics: what the heck are they talking about, this is just 
mathematically wrong, ill-defined or otherwise void of contents?)



Cristian Baboi wrote:

How can be Clean similar to Haskell and at the same time satisfy 9-12 ?


In Clean, print has the type

   print :: (Int - Int) - Dynamic

but there is (hopefully) no equality on  Dynamic . But it can be stored 
in a file or something


   store :: Dynamic - IO ()

and loaded back. Thanks to IO, we can think of the file contents to be a 
non-deterministically chosen intentional representation for a value with 
extensional equality.


I don't know whether Clean really does  store  that way, it may do more 
and hence break the extensional semantics a bit.



Regards,
apfelmus

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


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

2007-12-28 Thread Cristian Baboi
On Fri, 28 Dec 2007 16:34:23 +0200, apfelmus [EMAIL PROTECTED]  
wrote:



Jules Bean wrote:

Cristian Baboi wrote:

But I guess it won't work because the compiler will optimize it
and the call will disappear.


I'm not quite sure what you're trying to say here.


(That's the world view on Haskell issue I mean. I know this feeling  
with physics: what the heck are they talking about, this is just  
mathematically wrong, ill-defined or otherwise void of contents?)



Let me ask you 3 simple questions.
Can one use Haskell to make dynamically linked libraries (DLL on Windows,  
so on Linux) ?


If yes, what is in them ?
If not, why not ?



 Information from NOD32 
This message was checked by NOD32 Antivirus System for Linux Mail Servers.
 part000.txt - is OK
http://www.eset.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Missing join and split

2007-12-28 Thread Benja Fallenstein
Hi all,

On Dec 28, 2007 12:38 PM, Andrew Coppin [EMAIL PROTECTED] wrote:
 For joining you probably want some combination of intersperse and
 concat, e.g.

   unlines = concat . intersperse \n

And that's what we have :-)

Data.List.intercalate :: [a] - [[a]] - [a]
Data.List.intercalate x = concat . intersperse x

 For splitting, do we split on a given character? A predicate? Do we keep
 the splitting character or throw it away? Do we generate empty sublists
 or elide them? Apparently nobody can agree on these points, and writing
 a function with all possible options would be very messy...

If you use intercalate to join, I would presume that you would want to
use an inverse of it to split. I'd write it like this:

split :: Eq a = [a] - [a] - [[a]]
split at xs | Just xs' - stripPrefix at xs = [] : split at xs'
split at (x:xs) = (x:r) : rs where (r:rs) = split at xs
split at [] = [[]]

--with, if your version of the libraries is as old as mine and doesn't
have Data.List.stripPrefix,

stripPrefix (p:ps) (x:xs) | p == x = stripPrefix ps xs
stripPrefix [] xs  = Just xs
stripPrefix _  _   = Nothing

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


[Haskell-cafe] translating some C# abstractions into Haskell....

2007-12-28 Thread Nicholls, Mark
Lets say I've got 

Interface IFooX,Y
Where X : IBar
Where Y : IBar
{
}


Would seem to translate roughly to

class (IBar x, IBar y) = IFoo foo x y

? (or does it?)


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Nicholls, Mark
Sent: 28 December 2007 11:30
To: Chaddaï Fouché
Cc: haskell-cafe@haskell.org
Subject: RE: [Haskell-cafe] what does @ mean?.

Lovelythank you very muchanother small step forward.

-Original Message-
From: Chaddaï Fouché [mailto:[EMAIL PROTECTED] 
Sent: 28 December 2007 11:29
To: Nicholls, Mark
Cc: Alfonso Acosta; haskell-cafe@haskell.org
Subject: Re: [Haskell-cafe] what does @ mean?.

2007/12/28, Nicholls, Mark [EMAIL PROTECTED]:
 So in the example given...

 mulNat a b
  | a = b = mulNat' a b b
  | otherwise = mulNat' b a a
  where
   mulNat' x@(S a) y orig
   | x == one = y
   | otherwise = mulNat' a (addNat orig y) orig

 Is equivalent to

 mulNat a b
  | a = b = mulNat' a b b
  | otherwise = mulNat' b a a
  where
   mulNat' (S a) y orig
   | (S a) == one = y
   | otherwise = mulNat' a (addNat orig y) orig

 ?

Yes, but in the second version, it has to reconstruct (S a) before
comparing it to one where in the first it could do the comparison
directly. In this cas there may be some optimisation involved that
negate this difference but in many case it can do a real performance
difference.
The as-pattern (@ means as) is both practical and performant in most cases.

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


Re: [Haskell-cafe] Missing join and split

2007-12-28 Thread David Roundy
On Dec 28, 2007 9:51 AM, Benja Fallenstein [EMAIL PROTECTED] wrote:
 If you use intercalate to join, I would presume that you would want to
 use an inverse of it to split. I'd write it like this:

But alas, words and lines differ on how properly to split, so there's
no hint from the standard library which is preferred.  Of course,
there is no inverse to intercalate, so if you want to use a logical
approach, perhaps you'd want to define split first, and then define
your join as the inverse of split.  Darcs uses this latter approach,
which gives us a version of lines that isn't quite the same as the
one in the prelude.

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


Re: [Haskell-cafe] Missing join and split

2007-12-28 Thread Benja Fallenstein
On Dec 28, 2007 3:55 PM, David Roundy [EMAIL PROTECTED] wrote:
 On Dec 28, 2007 9:51 AM, Benja Fallenstein [EMAIL PROTECTED] wrote:
  If you use intercalate to join, I would presume that you would want to
  use an inverse of it to split. I'd write it like this:

 Of course, there is no inverse to intercalate

Right; I misspoke. What I meant was that you would want a split such that

intercalate a (split a xs) = a

for finite, total (a,xs) (and, since it's achievable, even for
infinite xs). Of course, (split a xs = [xs]) satisfies that, but if we
add the requirement that split is also supposed to do its job :-) then
I think split is fully specified except for whether (split a [] = [])
or (split a [] = [[]]). The latter seems better to me; e.g., it
satisfies

split a (x ++ a ++ y) = split a x ++ split a y

 so if you want to use a logical
 approach, perhaps you'd want to define split first, and then define
 your join as the inverse of split.

If your join comes out as being intercalate, I suppose it's six of
one, half a dozen of the other :-)

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


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

2007-12-28 Thread Luke Palmer
On Dec 28, 2007 5:58 AM, Cristian Baboi [EMAIL PROTECTED] wrote:
 Here is how I want print to be in Haskell

 print :: (a-b) - (a-b)

 with print = id, but the following side effect:

 - I want to call the print function today, and get the value tomorrow.

You might be interested in the standard module Debug.Trace, which
defines a function:

   trace :: String - b - b

Which allows you to print something avoiding the IO monad as you seem
to want.  Then to get
your print function, all you would need is a Show instance for a - b:

   print f = trace (show f) f

Then the Show instance:

   instance Show (a - b) where
   show f = function

And there you have it.  It's not very useful, since it just prints
function for every function, but there you go.  I suspect you want
to print some serialization of the function such that it can be read
in again and executed later.  You're not gonna get that any time soon.

But I also suspect that there is another legitimate solution to your
problem.  Unless the problem has to do with transferring *arbitrary*
functions (that is, your program knows nothing at all about what is
transferred) between processes (not to be confused with threads, which
Haskell is very good at).

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


Re: [Haskell-cafe] Missing join and split

2007-12-28 Thread Benja Fallenstein
On Dec 28, 2007 4:24 PM, Benja Fallenstein [EMAIL PROTECTED] wrote:
 Right; I misspoke. What I meant was that you would want a split such that

 intercalate a (split a xs) = a

 for finite, total (a,xs) (and, since it's achievable, even for
 infinite xs). Of course, (split a xs = [xs]) satisfies that, but if we
 add the requirement that split is also supposed to do its job :-) then
 I think split is fully specified except for whether (split a [] = [])
 or (split a [] = [[]]).

I take that back; it doesn't specify whether (split xx xxx) should
be [,x] or [x,]. I prefer the former, because working
left-to-right seems natural, and because it makes split more lazy (it
can yield (:_) before evaluating the input enough to see the third
'x').

 The latter seems better to me; e.g., it
 satisfies

 split a (x ++ a ++ y) = split a x ++ split a y

I take that back, too:

split xx  = [,,]
split xx x ++ split xx xxx = [x] ++ [,x]

(...but, still... :-))

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


[Haskell-cafe] Re: what does @ mean?.....

2007-12-28 Thread Ben Franksen
Achim Schneider wrote:

 ChrisK [EMAIL PROTECTED] wrote:
 
 zeroNothing Nothing = Nothing
 zeroNothing (Just n) =
   if n == 0 then Nothing else (Just n)
 
 versus
 
 zeroNothing Nothing = Nothing
 zeroNothing x@(Just n) =
   if n == 0 then Nothing else x
 
 versus
 
 zeroNothing Nothing = Nothing
 zeroNothing x =
 let (Just n) = x
 in if n == 0 then Nothing else x
 
 so, @ is kind of like a let, just with its arguments flipped.

However, if  x@(Just n)  fails to match, the next clause is chosen, whereas
the variable pattern  x  matches always. Thus, the last version works only
because the other possible case (Nothing) has already been handled. IOW, in
the second version of zeroNothing you may swap the order of patterns, but
not in the third one.

Cheers
Ben

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


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

2007-12-28 Thread Wolfgang Jeltsch
Am Freitag, 28. Dezember 2007 07:49 schrieben Sie:
 On Thu, 27 Dec 2007 18:19:47 +0200, Wolfgang Jeltsch
 [EMAIL PROTECTED] wrote:
  Am Donnerstag, 27. Dezember 2007 16:34 schrieb Cristian Baboi:
  I'll have to trust you, because I cannot test it.
 
  let x=(1:x); y=(1:y) in x==y .
 
  I also cannot test this:
 
  let x=(1:x); y=1:1:y in x==y
 
  In these examples, x and y denote the same value but the result of x ==
  y is _|_ (undefined) in both cases.  So (==) is not really equality in
  Haskell but a kind of weak equality: If x doesn’t equal y, x == y is
  False, but if x equals y, x == y might be True or undefined.

 Thank you.

 I can only notice that y always has an even number of 1, which is not the
 case for x :-)

Both have an infinite number of 1.  Why do you say “always”?  It seems that 
you think of x and y as “variables” whose values change over time.  This is 
not the case.  They both have a single value for all time: the infinite list 
consisting only of 1.

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


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

2007-12-28 Thread Wolfgang Jeltsch
Am Freitag, 28. Dezember 2007 07:49 schrieben Sie:
 On Thu, 27 Dec 2007 18:14:53 +0200, Wolfgang Jeltsch

 [EMAIL PROTECTED] wrote:
  Am Donnerstag, 27. Dezember 2007 15:53 schrieb Cristian Baboi:
  On Thu, 27 Dec 2007 16:50:10 +0200, Lennart Augustsson
 
  [EMAIL PROTECTED] wrote:
   Absolutly.  Every expression in Haskell denotes a value.
   Now, we've not agreed what value means, but to me it is a value. :)
 
  It is one value, or several ?
 
  It is one value with parts that are values themselves.

 It is one value or a SET of values ?
 What are the parts ?

A set of values is again a value.  So is a list of values.  This is similar to 
C++ where a field of an object can again be an object.

[1..] is a value of type [Int] and every element can be considered a part of 
this value.

Best wishes,
Wolfgang

P.S.: Didn’t send this to the list in the first place.  I don’t like mailing 
lists which don’t set the Reply-To: field.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2007-12-28 Thread Wolfgang Jeltsch
Am Freitag, 28. Dezember 2007 08:12 schrieb Cristian Baboi:
 On Thu, 27 Dec 2007 17:35:54 +0200, Jonathan Cast

 [EMAIL PROTECTED] wrote:
  Only on Von Neuman machines.  Haskell implementations are not required
  to run on Von Neuman machines.  That's why the language is called
  functional.  (Imperative languages, by contrast, are just abstractions
  of the underlying Von Neuman architecture, which is probably the source
  of your confusion).

 Can you tell me what is it that make a language imperative ?

 When I learned about formal grammars and languages, there was no
 discussion about this.

This is because a formal language (set of words) only consideres the syntactic 
aspect and formal grammars are only about describing formal languages.  In 
contrast, imperative vs. declarative is about semantics.  A language is 
imperative if programs written in this language say how something should be 
done instead of what should be the outcome.  This description is rather 
informal, of course.

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


Re: [Haskell-cafe] what does @ mean?.....

2007-12-28 Thread Serge LE HUITOUZE

Jedaï wrote:
 [...]
 Yes, but in the second version, it has to reconstruct (S a) before
 comparing it to one where in the first it could do the comparison
 directly. In this cas there may be some optimisation involved that
 negate this difference but in many case it can do a real performance
 difference.
 The as-pattern (@ means as) is both practical and performant in most cases.

Chris wrote:
 The first example takes apart the (Just n) and later reconstructs (Just n).
 Unless the compiler is fairly clever, this will cause the new (Just n) to be a
 new allocation instead of reusing the input value.  The second form uses an

I tend to believe that the '@' notation is mere syntactic sugar.
Indeed, it seems to me that Haskell compilers need not to be very clever to
share the identical sub-expressions, for one very simple reason implied by
Haskell semantics: referential transparency.

Am I right, or am I missing something?

And, of course, I'm not saying that syntactic sugar is bad.
As Alfonso noted, it saves some typing and avoids screwing up while trying
to modify multiple occurrences of the same sub-expression.
And, an even more important I think, a software engineering benefit: It
emphasizes for the reader that we really are talking about the very same
thing at two (or more) different places.

--Serge



No virus found in this outgoing message.
Checked by AVG Free Edition. 
Version: 7.5.516 / Virus Database: 269.17.9/1198 - Release Date: 26/12/2007 
17:26
 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2007-12-28 Thread Jules Bean

Cristian Baboi wrote:

Let me ask you 3 simple questions.
Can one use Haskell to make dynamically linked libraries (DLL on 
Windows, so on Linux) ?


The short answer is yes.

The long answer is that this is not a feature of haskell, but rather a 
feature of certain programs, which happen to be mostly but not entirely 
written in haskell, in particular, the haskell compiler. GHC can produce 
dynamically linked libraries.




If yes, what is in them ?


Object code, mostly. Sometimes a little data.

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


[Haskell-cafe] Re: FFIpointer data types question

2007-12-28 Thread Ben Franksen
Galchin Vasili wrote:
  If I am calling a ANSI function that requires a pointer to a C
  struct,
 which FFI pointer type should use?

A commonly used technique is to declare an empty data type

  data MyStruct

and then use

  Ptr MyStruct

in the FFI call. This is useful if the C struct is opaque, or at least meant
to be opaque (i.e. you are not allowed to access its elements directly).

For non-opaque structs, use a Haskell record and make it an instance of 
class Storable . An example:

struct timeval
  {
__time_t tv_sec;/* Seconds.  */
__suseconds_t tv_usec;  /* Microseconds.  */
  };

---

  data Timeval = Timeval {
  tv_sec :: TimeT,
  tv_usec :: USecondsT
}

(with suitable definitions of TimeT and USecondsT)

  instance Storable Timeval where
...

and your FFI calls will get a  Ptr Timeval  as argument.

HTH
Ben

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


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

2007-12-28 Thread Cristian Baboi
On Fri, 28 Dec 2007 18:32:05 +0200, Jules Bean [EMAIL PROTECTED]  
wrote:



Cristian Baboi wrote:

Let me ask you 3 simple questions.
Can one use Haskell to make dynamically linked libraries (DLL on  
Windows, so on Linux) ?


The short answer is yes.


The long answer is that this is not a feature of haskell, but rather a  
feature of certain programs, which happen to be mostly but not entirely  
written in haskell, in particular, the haskell compiler. GHC can produce  
dynamically linked libraries.


What you choose not to notice is the context in which I asked these  
questions.

The context is: Haskell functions as first-class objects.
What I am interested in the first place is dynamically linked libraries  
written in Haskell and used in Haskell.

The interface with other languages like C come second.


 If yes, what is in them ?



Object code, mostly. Sometimes a little data.


What is the definition of an entry point in Haskell ?
What is the semantics of those entry points ?


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


[Haskell-cafe] Re: what does @ mean?.....

2007-12-28 Thread Achim Schneider
Ben Franksen [EMAIL PROTECTED] wrote:

 Achim Schneider wrote:
 
 ChrisK [EMAIL PROTECTED] wrote:
 
 zeroNothing Nothing = Nothing
 zeroNothing (Just n) =
   if n == 0 then Nothing else (Just n)
 
 versus
 
 zeroNothing Nothing = Nothing
 zeroNothing x@(Just n) =
   if n == 0 then Nothing else x
 
 versus
 
 zeroNothing Nothing = Nothing
 zeroNothing x =
 let (Just n) = x
 in if n == 0 then Nothing else x
 
 so, @ is kind of like a let, just with its arguments flipped.
 
 However, if  x@(Just n)  fails to match, the next clause is chosen,
 whereas the variable pattern  x  matches always. Thus, the last
 version works only because the other possible case (Nothing) has
 already been handled. IOW, in the second version of zeroNothing you
 may swap the order of patterns, but not in the third one.
 
Actually, I considered working it out to

nothingIf :: (a - Bool) - Maybe a - Maybe a
nothingIf f m = m = (\j - if f j then Nothing else Just j)

nothingIf' :: (a - Bool) - Maybe a - Maybe a
nothingIf' f m = m = (\j - if f j then Nothing else m)

zeroNothing = nothingIf (== 0)
zeroNothing' = nothingIf' (== 0)

, but was too lazy. Hopefully only because it completely messes up my
point.

OTOH, 

zeroIf :: MonadPlus m = (a - Bool) - m a - m a
zeroIf f m = m = (\nz - if f nz then mzero else m)

zeroZero :: (MonadPlus m, Num a) = m a - m a
zeroZero = zeroIf (==0)

makes it interesting again as you can't construct a Just value with it.

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


RE: [Haskell-cafe] Missing join and split

2007-12-28 Thread Lihn, Steve
Programmer with perl background would think split like:
  list of string = split regex original string
Since regex is involved, it is specific to (Byte)String, not a generic
list. Also it appears one would need help from Text.Regex(.PCRE) to do
that.

 intercalate a (split a xs) = a
This identity rule does not hold for perl's join/split if regex is used.

Steve  

-Original Message-
On Dec 28, 2007 4:24 PM, Benja Fallenstein [EMAIL PROTECTED]
wrote:
 Right; I misspoke. What I meant was that you would want a split such
that

 intercalate a (split a xs) = a




--
Notice:  This e-mail message, together with any attachments, contains
information of Merck  Co., Inc. (One Merck Drive, Whitehouse Station,
New Jersey, USA 08889), and/or its affiliates (which may be known
outside the United States as Merck Frosst, Merck Sharp  Dohme or MSD
and in Japan, as Banyu - direct contact information for affiliates is 
available at http://www.merck.com/contact/contacts.html) that may be 
confidential, proprietary copyrighted and/or legally privileged. It is 
intended solely for the use of the individual or entity named on this 
message. If you are not the intended recipient, and have received this 
message in error, please notify us immediately by reply e-mail and then 
delete it from your system.

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


Re: [Haskell-cafe] what does @ mean?.....

2007-12-28 Thread Jules Bean

Serge LE HUITOUZE wrote:

I tend to believe that the '@' notation is mere syntactic sugar.
Indeed, it seems to me that Haskell compilers need not to be very clever to
share the identical sub-expressions, for one very simple reason implied by
Haskell semantics: referential transparency.

Am I right, or am I missing something?


You are missing that modifying a program in a way which adds sharing can 
have disastrous performance effects.


In particular, adding sharing can stop something being GCed, which can 
convert an algorithm which runs in linear time and constant space to one 
which runs in linear space (and therefore, perhaps, quadratic time).


Therefore compilers have to be conservative about adding sharing.

In general, sharing in GHC-compiled programs is specified rather 
explicitly: sharing is naming, so things which are names (let-bound or 
pattern-bound) are guaranteed shared and normally nothing else.


You can *imagine* a compiler being cleverer about this. It turns out to 
be an interesting but hard problem.


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


Re: [Haskell-cafe] what does @ mean?.....

2007-12-28 Thread Luke Palmer
On Dec 28, 2007 9:35 AM, Jules Bean [EMAIL PROTECTED] wrote:
 In particular, adding sharing can stop something being GCed, which can
 convert an algorithm which runs in linear time and constant space to one
 which runs in linear space (and therefore, perhaps, quadratic time).

I've heard of this before, but can you give an example?

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


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

2007-12-28 Thread Achim Schneider
Wolfgang Jeltsch [EMAIL PROTECTED] wrote:

 Am Freitag, 28. Dezember 2007 07:49 schrieben Sie:
  On Thu, 27 Dec 2007 18:19:47 +0200, Wolfgang Jeltsch
  [EMAIL PROTECTED] wrote:
   Am Donnerstag, 27. Dezember 2007 16:34 schrieb Cristian Baboi:
   I'll have to trust you, because I cannot test it.
  
   let x=(1:x); y=(1:y) in x==y .
  
   I also cannot test this:
  
   let x=(1:x); y=1:1:y in x==y
  
   In these examples, x and y denote the same value but the result
   of x == y is _|_ (undefined) in both cases.  So (==) is not
   really equality in Haskell but a kind of weak equality: If x
   doesn’t equal y, x == y is False, but if x equals y, x == y might
   be True or undefined.
 
  Thank you.
 
  I can only notice that y always has an even number of 1, which is
  not the case for x :-)
 
 Both have an infinite number of 1.  Why do you say “always”?  It
 seems that you think of x and y as “variables” whose values change
 over time.  This is not the case.  They both have a single value for
 all time: the infinite list consisting only of 1.
 
Does that then mean that
[1] = [1,1]
?

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


Re: [Haskell-cafe] Doing some things right

2007-12-28 Thread Alex Sandro Queiroz e Silva

Hallo,

Andrew Coppin escreveu:
[I actually heard a number of people tell me that learning LISP would 
change my life forever because LISP has something called macros. I 
tried to learn it, and disliked it greatly. It's too messy. And what 
the heck is cdr ment to mean anyway? To me, LISP doesn't even seem 
all that different from normal languages (modulo weird syntax). Now 
Haskell... that's FUN!]


Macros are not the only thing that makes Lisp (it hasn't been 
called LISP for ages) great, but surely contributes for that. 
Unfortunately Lisp is like the Matrix, you can't be told how great it 
is, you have to see for yourself.


Cheers,
-alex

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


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

2007-12-28 Thread Daniel Fischer
Am Freitag, 28. Dezember 2007 17:27 schrieb Achim Schneider:

  Both have an infinite number of 1.  Why do you say “always”?  It
  seems that you think of x and y as “variables” whose values change
  over time.  This is not the case.  They both have a single value for
  all time: the infinite list consisting only of 1.

 Does that then mean that
 [1] = [1,1]
 ?

No, it means you cannot distinguish (repeat 1) from (cycle [1,1]).

Is infinity an even number or an odd one?

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


Re: [Haskell-cafe] Doing some things right

2007-12-28 Thread Brian Sniffen
On Dec 28, 2007 6:05 AM, Andrew Coppin [EMAIL PROTECTED] wrote:
 [I actually heard a number of people tell me that learning LISP would
 change my life forever because LISP has something called macros. I
 tried to learn it, and disliked it greatly. It's too messy. And what the
 heck is cdr ment to mean anyway? To me, LISP doesn't even seem all
 that different from normal languages (modulo weird syntax). Now
 Haskell... that's FUN!]

Contents of Data Register.

Macros are like Template Haskell.  One example of where they're useful
is programmer definition of new binding forms.  That's not possible in
Haskell without Templates.  Macros were invented in Lisp because the
syntax is so easy for machine manipulation---they don't have a tenth
the complexity of Template Haskell for about the same power.

-Brian

-- 
Brian T. Sniffen
[EMAIL PROTECTED]or[EMAIL PROTECTED]
http://www.evenmere.org/~bts
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2007-12-28 Thread ChrisK
This thread is obviously a source of much fun.  I will play too.

Cristian Baboi wrote:
 On Fri, 28 Dec 2007 18:32:05 +0200, Jules Bean [EMAIL PROTECTED]
 wrote:
 
 Cristian Baboi wrote:
 Let me ask you 3 simple questions.
 Can one use Haskell to make dynamically linked libraries (DLL on
 Windows, so on Linux) ?

 The short answer is yes.
 
 The long answer is that this is not a feature of haskell, but rather a
 feature of certain programs, which happen to be mostly but not
 entirely written in haskell, in particular, the haskell compiler. GHC
 can produce dynamically linked libraries.
 
 What you choose not to notice is the context in which I asked these
 questions.
 The context is: Haskell functions as first-class objects.
 What I am interested in the first place is dynamically linked libraries
 written in Haskell and used in Haskell.
 The interface with other languages like C come second.
 
  If yes, what is in them ?
 
 Object code, mostly. Sometimes a little data.
 
 What is the definition of an entry point in Haskell ?

Haskell does not have such a concept.  At all.  An implementation may have
such a concept.

Most people on this list define Haskell as any attempt at an implementation of
one of the standards which define Haskell, most recently the Hakell 98 standard.

This can be nhc / yhc / ghc / hugs / winhugs / helium / jhc.  Some of these
compile to native code, some compile to byte code for a virtual machine.  If an
implementation can compile separately, then it might support dynamic libraries.
 If so then a specific version of that compiler will define its own
implementation specific concept of an entry point.

 What is the semantics of those entry points ?

It depends.  For recent ghc versions, see its user manual:
http://haskell.org/ghc/docs/latest/html/users_guide/ffi-ghc.html#ffi-library
http://haskell.org/ghc/docs/latest/html/users_guide/win32-dlls.html

Other note:
  An imperative language, such as C++ or Java, specified the binary output of
any instance of the compiler.  Class methods will have very specific names and
addresses.  In C++ you can even get the member-function pointer values and
examine the byte offsets in the object.  In Java one gets a very specific layout
of bytecode in a class file.

  Haskell is a declarative language.  It does not specify anything about the
implementation's internals.  It specifies only properties like non-strict.
The fact that ghc uses lazy evaluation is merely an implementation detail,
chosen as a way of satisfying the non-strict requirement of Haskell.  The
output of a Haskell compiler is free to take all the source code and implement
things with jumps and branches that look absolutely nothing like function calls.

-- 
Chris

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


[Haskell-cafe] Re: Missing join and split

2007-12-28 Thread ChrisK
Lihn, Steve wrote:
 Programmer with perl background would think split like:
   list of string = split regex original string
 Since regex is involved, it is specific to (Byte)String, not a generic
 list. Also it appears one would need help from Text.Regex(.PCRE) to do
 that.
 
 intercalate a (split a xs) = a
 This identity rule does not hold for perl's join/split if regex is used.
 
 Steve  
 

Well, libpcre does not have a split function.

One can already write a split that uses the high level Regex API.  The only
reason you might want to dig into regex-pcre's Text.Regex.PCRE would be if it
would help efficiency.

Specifically, regex-base defines a RegexContext instance which is:

( RegexLike a b = RegexContext a b (b, b, b) ) : The text before the match, the
text of the match, the text after the match

So you can iteratively generate the pieces that split returns.

-- 
Chris

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


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

2007-12-28 Thread Cristian Baboi

On Fri, 28 Dec 2007 18:27:29 +0200, Achim Schneider [EMAIL PROTECTED] wrote:


Wolfgang Jeltsch [EMAIL PROTECTED] wrote:


Am Freitag, 28. Dezember 2007 07:49 schrieben Sie:
 On Thu, 27 Dec 2007 18:19:47 +0200, Wolfgang Jeltsch
 [EMAIL PROTECTED] wrote:
  Am Donnerstag, 27. Dezember 2007 16:34 schrieb Cristian Baboi:
  I'll have to trust you, because I cannot test it.
 
  let x=(1:x); y=(1:y) in x==y .
 
  I also cannot test this:
 
  let x=(1:x); y=1:1:y in x==y
 
  In these examples, x and y denote the same value but the result
  of x == y is _|_ (undefined) in both cases.  So (==) is not
  really equality in Haskell but a kind of weak equality: If x
  doesn’t equal y, x == y is False, but if x equals y, x == y might
  be True or undefined.

 Thank you.

 I can only notice that y always has an even number of 1, which is
 not the case for x :-)

Both have an infinite number of 1.  Why do you say “always”?  It
seems that you think of x and y as “variables” whose values change
over time.  This is not the case.  They both have a single value for
all time: the infinite list consisting only of 1.



Does that then mean that
[1] = [1,1]


No. If you try to learn Haskell don't listen to  me. :-)

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


[Haskell-cafe] Re: Doing some things right

2007-12-28 Thread ChrisK
Brian Sniffen wrote:
 On Dec 28, 2007 6:05 AM, Andrew Coppin [EMAIL PROTECTED] wrote:
 [I actually heard a number of people tell me that learning LISP would
 change my life forever because LISP has something called macros. I
 tried to learn it, and disliked it greatly. It's too messy. And what the
 heck is cdr ment to mean anyway? To me, LISP doesn't even seem all
 that different from normal languages (modulo weird syntax). Now
 Haskell... that's FUN!]
 
 Contents of Data Register.
 
 Macros are like Template Haskell.  One example of where they're useful
 is programmer definition of new binding forms.  That's not possible in
 Haskell without Templates.  Macros were invented in Lisp because the
 syntax is so easy for machine manipulation---they don't have a tenth
 the complexity of Template Haskell for about the same power.
 
 -Brian
 

There is also Likell, at http://liskell.org/ by Clemens Fruhwir, which
translates Haskell source into a lisp style prefix syntax (will (all (the
(parentheses.  This is to allow macro-like analysis and transformation
without template haskell.

The main use of template haskell that I have seen mentioned on the mailing lists
is to analyze a data declaration and auto-generate some new class and
instance declarations.

But I agree that template haskell has problems:
  (*) Its own syntax, as big and complicated as Haskell
  (*) Has historically been very poorly documented (that _might_ have changed)
  (*) Only works with ghc

-- 
Chris

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


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

2007-12-28 Thread Cristian Baboi
On Fri, 28 Dec 2007 19:18:33 +0200, ChrisK [EMAIL PROTECTED]  
wrote:



This thread is obviously a source of much fun.  I will play too.


Well, it starts with Wikipedia ... :-)



What is the definition of an entry point in Haskell ?


Haskell does not have such a concept.  At all.  An implementation may  
have

such a concept.


Then a Haskell module know nothing about them.

Most people on this list define Haskell as any attempt at an  
implementation of
one of the standards which define Haskell, most recently the Hakell 98  
standard.


This can be nhc / yhc / ghc / hugs / winhugs / helium / jhc.  Some of  
these
compile to native code, some compile to byte code for a virtual  
machine.  If an
implementation can compile separately, then it might support dynamic  
libraries.

 If so then a specific version of that compiler will define its own
implementation specific concept of an entry point.


How can one make portable dynamic libraries then ?


What is the semantics of those entry points ?



It depends.  For recent ghc versions, see its user manual:
http://haskell.org/ghc/docs/latest/html/users_guide/ffi-ghc.html#ffi-library
http://haskell.org/ghc/docs/latest/html/users_guide/win32-dlls.html


The conclusion:

Portable Haskell Dynamic libraries does not exists.

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


Re: [Haskell-cafe] what does @ mean?.....

2007-12-28 Thread Jules Bean

Luke Palmer wrote:

On Dec 28, 2007 9:35 AM, Jules Bean [EMAIL PROTECTED] wrote:

In particular, adding sharing can stop something being GCed, which can
convert an algorithm which runs in linear time and constant space to one
which runs in linear space (and therefore, perhaps, quadratic time).


I've heard of this before, but can you give an example?


Sure:

foo (length (build_big_list 1 2 3)) (build_big_list 1 2 3)

Here, foo is a function which operates on a list, but needs to know 
the length of the list for some reason.


As written, build_big_list is called twice. This is potentially a waste 
of time, but it *does* mean that if the big list is very  very big 
(larger than available memory) but build_big_list is a good producer, it 
can be produced and GCed in constant space - as long as length is a good 
consumer (which it is) and as long as foo is (can't tell without seeing 
the definition, obviously!)


So, you can do a two-pass algorithm in two-passes, but in constant space.

Now, if we automatically share those two, we get something like this:

let l = build_big_list 1 2 3 in foo (length l) l

which *looks* like an optimisation, but the shared 'l' will be kept 
around. The length will be calculated first (assuming foo uses the 
length, that is) and then the entire list kept in memory while foo 
processes it.


Of course, it's hard to see this kind of problem with the simple x@(Just 
y) case we were talking about, but if your function calls itself 
recursively then it can.


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


Re: [Haskell-cafe] Doing some things right

2007-12-28 Thread Ketil Malde
Andrew Coppin [EMAIL PROTECTED] writes:

 
 http://www.cs.kuleuven.ac.be/%7Edtai/projects/ALP//newsletter/dec07/content/Articles/tom/content.html

 Haskell is the undisputed flagship of the FP community.

 Er... really? 

It depends on how you define the FP community, of course.  The
author counts participation at ICFP, so he probably has an academic
slant. 

 I thought Lisp and Erlang were both infinitely more
 popular and better known. 

Certainly not infinitely.  Lisp isn't entirely functional, and while
Erlang is an industrial success story, I think Haskell is seeing a
wider range of application.

 [I actually heard a number of people tell me that learning LISP would
 change my life forever because LISP has something called macros.

The close ties between data and code in Lisp gives some nice
opportunities for your program to e.g. manipulate itself.  For
e.g. genetic programming.

I think macros are used for bottom-up design (i.e. building EDSLs),
where you would use higher-order functions in Haskell.

(I don't really have a lot of Lisp experience, I'd be interested to
hear if other people agree or not)

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] OT: ghc 6.8 in Debian?

2007-12-28 Thread Magnus Therning
It seems my emails to the Debian Haskell list (CC'd on this email as
well) are silently dropped :-(  Since I suspect the readers of /that/
list are likely to be on this one as well I thought I'd give this a try.

What's happening with GHC 6.8 in Debian?

There was an email about a month ago announcing the availability of the
core package.  Since then it seems very little has happened.  What can I
do to help, if anything?

/M

-- 
Magnus Therning (OpenPGP: 0xAB4DFBA4)
magnus@therning.org Jabber: magnus.therning@gmail.com
http://therning.org/magnus

What if I don't want to obey the laws? Do they throw me in jail with
the other bad monads?
 -- Daveman



signature.asc
Description: OpenPGP digital signature
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: [Debian-haskell] OT: ghc 6.8 in Debian?

2007-12-28 Thread Ganesh Sittampalam

On Fri, 28 Dec 2007, Magnus Therning wrote:


It seems my emails to the Debian Haskell list (CC'd on this email as
well) are silently dropped :-(


I don't believe that's the case; I've been getting them, and they're in 
the archive: 
http://urchin.earth.li/pipermail/debian-haskell/2007-December/thread.html


Cheers,

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


Re: [Haskell-cafe] Doing some things right

2007-12-28 Thread Andrew Coppin

Brian Sniffen wrote:

On Dec 28, 2007 6:05 AM, Andrew Coppin [EMAIL PROTECTED] wrote:
  

[I actually heard a number of people tell me that learning LISP would
change my life forever because LISP has something called macros. I
tried to learn it, and disliked it greatly. It's too messy. And what the
heck is cdr ment to mean anyway? To me, LISP doesn't even seem all
that different from normal languages (modulo weird syntax). Now
Haskell... that's FUN!]



Contents of Data Register.
  


Right. I've heard the story about why it came to be called that, but 
seriously... I can never remember whether I want cdr or car. It's a 
silly choice of name. [Sure, you can rename it. And then nobody but you 
will understand it.]



Macros are like Template Haskell.


Which, incidentally, I also don't use. ;-)

Doesn't Derive cover most of the useful cases for TH?

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


Re: [Haskell-cafe] Doing some things right

2007-12-28 Thread Alex Sandro Queiroz e Silva

Hallo,

Andrew Coppin escreveu:

Brian Sniffen wrote:
On Dec 28, 2007 6:05 AM, Andrew Coppin [EMAIL PROTECTED] 
wrote:
 

[I actually heard a number of people tell me that learning LISP would
change my life forever because LISP has something called macros. I
tried to learn it, and disliked it greatly. It's too messy. And what 
the

heck is cdr ment to mean anyway? To me, LISP doesn't even seem all
that different from normal languages (modulo weird syntax). Now
Haskell... that's FUN!]



Contents of Data Register.
  


Right. I've heard the story about why it came to be called that, but 
seriously... I can never remember whether I want cdr or car. It's a 
silly choice of name. [Sure, you can rename it. And then nobody but 
you will understand it.]


In Common Lisp, standardised in 1984, there are the equivalent 
functions FIRST and REST, which everyone know what they mean.


Cheers,
-alex

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


Re: [Haskell-cafe] Haskell-cafe reply-to etiquette

2007-12-28 Thread Albert Y. C. Lai

Justin Bailey wrote:

When I joined the haskell-cafe mailing list, I was surprised to see
the reply-to header on each message was set to the sender of a given
message to the list, rather than the list itself. That seemed counter
to other mailing lists I had been subscribed to, but I didn't think
too much about it.


In addition to agreeing with the article Reply-To Munging Considered 
Harmful, I want to remark that:


A. This mailing list does not set the Reply-To header whatsoever. Not 
even to the author. When you hit reply, the destination is taken from 
From, not Reply-To. Thus



I was surprised to see
the reply-to header on each message was set to the sender


was inaccurate.

B. This mailing list sets the List-Post header:

List-Post: mailto:haskell-cafe@haskell.org

Progressive mail clients honour this, e.g., Evolution. Thus you are 
given three buttons:


reply - Reply-To or From
reply all - all found addresses
reply to list - List-Post

In my opinion this is the way to go. The semantics of List-Post is 
clear cut. The semantics of Reply-To is too overloaded to be relied on.


I don't use Evolution - I am still at Thunderbird 1.5. It doesn't know 
the List-Post header. (But there may be plugins to add it.) But I do 
the little extra manual work of: reply all, then take out the author's 
address and just keep the list address. On the other hand, I completely 
don't mind receiving duplicates.


In my opinion, if I choose to use dumb software, I should be the one 
making up for it, not ask the whole world to fudge semantics to please 
my dumb software. Lowest common denominators are evil.

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


Re: [Haskell-cafe] Missing join and split

2007-12-28 Thread Albert Y. C. Lai

Mitar wrote:

I am really missing the (general) split function built in standard
Haskell. I do not understand why there is something so specific as
words and lines but not a simple split? The same goes for join.


Don't forget Text.Regex.splitRegex.

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


[Haskell-cafe] Function Stores

2007-12-28 Thread Cristian Baboi

Here is what I was able to come up with:


module Store where

data FStore1 a b  = Empty1 | FS1 ( a-b , FStore1 a b )

store1 :: (a-b) - (FStore1 a  b)
store1 f = let x = FS1 (f, x) in x

data FStore2 a b = Empty2 | FS2 ( a-b , FStore2 a b, FStore2 a b )

store2 :: (a-b) - (FStore2 a b)
store2 f = let x = FS2 (f,x,x) in x


First I tryed store1, but after a while it went out of business.
Second I tryed other business model with store2. Same result.

Then I tryed to make a street of stores.
After a while, they all went out of business.

Then I tryed to make several streets of stores.
After a while they all went out of business.

Then I tryed to make an infinite street of stores.
After a while they all went out of business.

Then, following some rumors that there is a store on that street with some  
function in stock that might be willing to give it away, I noticed that  
the street disappeared, and I cannot go to that store.


Can you help me find it ?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Doing some things right

2007-12-28 Thread Miguel Mitrofanov

I thought Lisp and Erlang were both infinitely more
popular and better known.


Certainly not infinitely.  Lisp isn't entirely functional, and while
Erlang is an industrial success story, I think Haskell is seeing a
wider range of application.


Well, it seems for me that Erlang is much less functional than Lisp.  
It's totally OO, in fact.

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


Re: [Haskell-cafe] Missing join and split

2007-12-28 Thread Mitar
Hi!

On Dec 28, 2007 5:51 PM, Lihn, Steve [EMAIL PROTECTED] wrote:
 Since regex is involved, it is specific to (Byte)String, not a generic
 list.

Oh, this gives me an interesting idea: making regular expressions more generic.

Would not it be interesting and useful (but not really efficient) to
have patterns something like:

foo :: Eq a = a - ...
foo (_{4}'b') = ...

which would match a list with four elements ending with an element 'b'. Or:

foo (_+';'_+';'_) = ...

which would match a list with embedded two ';' elements. (Last _
matched the remaining of the list.)

OK, maybe guards are not the proper place to implement this as would
add a possibility to make a really messy Haskell programs. But
extending regular expressions to work on any list of elements with
type implementing Eq would be realy powerfull. And then we could use
split in many other than just text processing contexts.

Of course, the problem in both cases is implementing something like
regular expressions efficiently, especially on lists, but this is why
there are smart people around. :-)


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


Re: [Haskell-cafe] Missing join and split

2007-12-28 Thread Evan Laforge
 Would not it be interesting and useful (but not really efficient) to
 have patterns something like:

 foo :: Eq a = a - ...
 foo (_{4}'b') = ...

 which would match a list with four elements ending with an element 'b'. Or:

 foo (_+';'_+';'_) = ...

Maybe you could use view patterns?

foo (regex (.*);(.*);(.*)) - [c1, c2, c3] = ...

 OK, maybe guards are not the proper place to implement this as would
 add a possibility to make a really messy Haskell programs. But
 extending regular expressions to work on any list of elements with
 type implementing Eq would be realy powerfull. And then we could use
 split in many other than just text processing contexts.

 Of course, the problem in both cases is implementing something like
 regular expressions efficiently, especially on lists, but this is why
 there are smart people around. :-)

Parser combinators basically provide generalized regexes, and they all
take lists of arbitrary tokens rather than just Chars.  I've written a
simple combinator library before that dispenses with all the monadic
goodness in favor of a group combinator and returning [Either [tok]
[tok]], which sort of gives parsers a simpler regexy flavor (Left is
out of group chunk and Right is in group chunk).

foo (match (group any `sepBy` char ';') - [c1, c2, c3]) = ...
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Doing some things right

2007-12-28 Thread Achim Schneider
Andrew Coppin [EMAIL PROTECTED] wrote:

 Brian Sniffen wrote:
  On Dec 28, 2007 6:05 AM, Andrew Coppin
  [EMAIL PROTECTED] wrote: 
  [I actually heard a number of people tell me that learning LISP
  would change my life forever because LISP has something called
  macros. I tried to learn it, and disliked it greatly. It's too
  messy. And what the heck is cdr ment to mean anyway? To me, LISP
  doesn't even seem all that different from normal languages (modulo
  weird syntax). Now Haskell... that's FUN!]
  
 
  Contents of Data Register.

 
 Right. I've heard the story about why it came to be called that, but 
 seriously... I can never remember whether I want cdr or car. It's a 
 silly choice of name. [Sure, you can rename it. And then nobody but
 you will understand it.]
 
That's not even the end of the fun: You can freely switch around car
and cdr, treating cdr as element of head and car as tail, and try
to put into words why that won't make a foldl out of a foldr. You can
also never put any useful value into any cons and still have it
represent something useful, or say caaaddaaadaddaddadadadaddar, at
which point you're hopefully lost. It's probably called dadaism.

Actually, if you read through the Wizard Book, at least half of the
defined functions are defined solely in terms of list, car, cdar,
cddar and so on.

One might be tempted to claim that any sufficiently complicated scheme
program  contains an informally-specified, bug-ridden implementation of
half of haskell's type system.

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


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

2007-12-28 Thread Lennart Augustsson
You are right, Portable Haskell Dynamic libraries do not exist because the
Haskell standard does not talk about them at all.
Portable C Dynamic libraries do not exist either.  Given POSIX they exist,
but if you happen upon a platform that only has a C compiler it won't have
them.

On Dec 28, 2007 7:08 PM, Cristian Baboi [EMAIL PROTECTED] wrote:

 On Fri, 28 Dec 2007 19:18:33 +0200, ChrisK [EMAIL PROTECTED]
 wrote:

  This thread is obviously a source of much fun.  I will play too.

 Well, it starts with Wikipedia ... :-)

 
  What is the definition of an entry point in Haskell ?

  Haskell does not have such a concept.  At all.  An implementation may
  have
  such a concept.

 Then a Haskell module know nothing about them.

  Most people on this list define Haskell as any attempt at an
  implementation of
  one of the standards which define Haskell, most recently the Hakell 98
  standard.

  This can be nhc / yhc / ghc / hugs / winhugs / helium / jhc.  Some of
  these
  compile to native code, some compile to byte code for a virtual
  machine.  If an
  implementation can compile separately, then it might support dynamic
  libraries.
   If so then a specific version of that compiler will define its own
  implementation specific concept of an entry point.

 How can one make portable dynamic libraries then ?

  What is the semantics of those entry points ?

  It depends.  For recent ghc versions, see its user manual:
 
 http://haskell.org/ghc/docs/latest/html/users_guide/ffi-ghc.html#ffi-library
  http://haskell.org/ghc/docs/latest/html/users_guide/win32-dlls.html

 The conclusion:

 Portable Haskell Dynamic libraries does not exists.

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

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


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

2007-12-28 Thread Ben Franksen
Bulat Ziganshin wrote:
 Hello Yitzchak,
 Thursday, December 27, 2007, 12:10:21 PM, you wrote:
 In particular,
 two functions are equal only if they produce
 the same value for every input, and in general it is
 impossible for a computer to check that.
 
 for a computer is superfluous here. people are not smarter than
 computers and can't do anything that's impossible for computers

I don't think my computer can be sorry, but I know I can be.

And don't forget that there are 'undecidable' problems.

Cheers
Ben

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


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

2007-12-28 Thread Ben Franksen
Wolfgang Jeltsch wrote:
 P.S.: Didn’t send this to the list in the first place.  I don’t like
 mailing lists which don’t set the Reply-To: field.

There are serious reasons not to, see
http://www.unicom.com/pw/reply-to-harmful.html

My personal suggestion is to try news.gmane.org (group:
gmane.comp.lang.haskell.cafe) and a news client. Makes life *so* much
easier, especially for high-volume lists like haskell-cafe. I switched a
few years ago and never wanted to go back.

Another trick: in kmail (which I see you are using) if you filter your
haskell-cafe traffic into a separate mail folder, you can configure this
folder to answer to the list per default, instead of the sender.

Cheers
Ben

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


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

2007-12-28 Thread Jonathan Cast

On 28 Dec 2007, at 3:13 PM, Ben Franksen wrote:


Bulat Ziganshin wrote:

Hello Yitzchak,
Thursday, December 27, 2007, 12:10:21 PM, you wrote:

In particular,
two functions are equal only if they produce
the same value for every input, and in general it is
impossible for a computer to check that.


for a computer is superfluous here. people are not smarter than
computers and can't do anything that's impossible for computers


I don't think my computer can be sorry, but I know I can be.

And don't forget that there are 'undecidable' problems.


Which I have never yet seen decided by a person...

jcc

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


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

2007-12-28 Thread Jonathan Cast

On 28 Dec 2007, at 1:15 AM, Cristian Baboi wrote:

On Thu, 27 Dec 2007 17:39:25 +0200, Jonathan Cast  
[EMAIL PROTECTED] wrote:


Haskell is not a computer programming language; Haskell  
implementations are not required to run on computers.  Haskell is  
a formal notation for computation (completely unrelated to the Von  
Neuman machine sitting on your desk).  It can be implemented on  
Von Neuman machines, because they are still universal Turing  
machines, but it is /not/ a radical attack on the problem of  
programming peripherals!


How do you call that thing that implement Haskell ?


Usually I call it a compiler for a computer.  That's a fact about  
economics, not about Haskell.


jcc

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


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

2007-12-28 Thread Jonathan Cast

On 28 Dec 2007, at 3:37 AM, Cristian Baboi wrote:


Thank you.

It sounds like a limit. xn -- x for n --  :-)


I could say that LUBs are colimits, not limits, but I won't :)

More seriously, I don't like the calculus -- notation in this  
context; these are suprema, not lims.




How can I get that maximal value when I start from a non maximal one ?


Take the least upper bound of a maximum set.



[1 .. ] and x=1:x are maximal ?


Yes.

jcc

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


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

2007-12-28 Thread Jonathan Cast

On 28 Dec 2007, at 4:10 AM, Cristian Baboi wrote:

On Fri, 28 Dec 2007 12:01:51 +0200, Miguel Mitrofanov  
[EMAIL PROTECTED] wrote:



It sounds like a limit. xn -- x for n --  :-)


Yeah, that's right.


If xn is monotone, then I only have to worry when it is not  
bounded, right ?


How can I get that maximal value when I start from a non maximal  
one ?


Not a problem. For example, const 1 maps each value (even (_|_))  
to the maximal value 1.



[1 .. ] and x=1:x are maximal ?


Can you give me some examples of non maximal ones ?


undefined, 1:undefined, 1:1:undefined, undefined:undefined, [1, 1,  
undefined], etc.


jcc

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


Re: [Haskell-cafe] Missing join and split

2007-12-28 Thread Mitar
Hi!

On Dec 29, 2007 12:13 AM, Evan Laforge [EMAIL PROTECTED] wrote:
 Maybe you could use view patterns?

 foo (regex (.*);(.*);(.*)) - [c1, c2, c3] = ...

Oh. Beautiful. :-)

 Parser combinators basically provide generalized regexes, and they all
 take lists of arbitrary tokens rather than just Chars.  I've written a
 simple combinator library before that dispenses with all the monadic
 goodness in favor of a group combinator and returning [Either [tok]
 [tok]], which sort of gives parsers a simpler regexy flavor (Left is
 out of group chunk and Right is in group chunk).

 foo (match (group any `sepBy` char ';') - [c1, c2, c3]) = ...

Ah. Is this accessible somewhere?


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


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

2007-12-28 Thread Jonathan Cast

On 28 Dec 2007, at 4:20 AM, Cristian Baboi wrote:


Thank you.

This is what I understand so far:

- the maximal values is what is usually called data


Incorrect.  Total functions are maximal.


- the non maximal are what is usually   called code


Incorrect.  `Non maximal' expressions are just expressions with  
embedded infinite loops or exceptions (or functions that yield such  
values when presented with defined arguments).


- in functional languages one can be given non maximal values  
(code) as input


Correct (sort of, se above).  But not in the way you think.  And only  
in non-strict functional languages.


jcc

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


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

2007-12-28 Thread Jonathan Cast

On 28 Dec 2007, at 4:40 AM, Cristian Baboi wrote:

On Fri, 28 Dec 2007 12:01:51 +0200, Miguel Mitrofanov  
[EMAIL PROTECTED] wrote:




[1 .. ] and x=1:x are maximal ?


Yes.



How can a Haskell implementation recognize a maximal value ?

x=1:x for example.


It can't.

jcc

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


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

2007-12-28 Thread Jonathan Cast

On 28 Dec 2007, at 8:42 AM, Cristian Baboi wrote:

On Fri, 28 Dec 2007 16:34:23 +0200, apfelmus  
[EMAIL PROTECTED] wrote:



Jules Bean wrote:

Cristian Baboi wrote:

But I guess it won't work because the compiler will optimize it
and the call will disappear.


I'm not quite sure what you're trying to say here.


(That's the world view on Haskell issue I mean. I know this  
feeling with physics: what the heck are they talking about, this  
is just mathematically wrong, ill-defined or otherwise void of  
contents?)



Let me ask you 3 simple questions.
Can one use Haskell to make dynamically linked libraries (DLL on  
Windows, so on Linux) ?


Haskell 98, no.  But GHC works fine.


If yes, what is in them ?


As has been said, object code.  Which is why you can't call GHC  
outside of the IO monad.



If not, why not ?


Because it's not portable.

These days, it is distressingly common to see the word `portable'  
used to mean `works on anything sufficiently willing to pretend it's  
a Unix'.  This depresses me; I think it's a failure of imagination,  
mostly.


jcc

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


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

2007-12-28 Thread Jonathan Cast

On 28 Dec 2007, at 12:08 PM, Cristian Baboi wrote:

On Fri, 28 Dec 2007 19:18:33 +0200, ChrisK  
[EMAIL PROTECTED] wrote:



This thread is obviously a source of much fun.  I will play too.


Well, it starts with Wikipedia ... :-)



What is the definition of an entry point in Haskell ?


Haskell does not have such a concept.  At all.  An  
implementation may have

such a concept.


Then a Haskell module know nothing about them.

Most people on this list define Haskell as any attempt at an  
implementation of
one of the standards which define Haskell, most recently the  
Hakell 98 standard.


This can be nhc / yhc / ghc / hugs / winhugs / helium / jhc.  Some  
of these
compile to native code, some compile to byte code for a virtual  
machine.  If an
implementation can compile separately, then it might support  
dynamic libraries.

 If so then a specific version of that compiler will define its own
implementation specific concept of an entry point.


How can one make portable dynamic libraries then ?


If by portable you mean, works on /both/ OSs, then GHC-specific  
should be portable enough for you...


jcc

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


[Haskell-cafe] Re: Function Stores

2007-12-28 Thread Achim Schneider
Cristian Baboi [EMAIL PROTECTED] wrote:

 Can you help me find it ?

Watch out for those garbage collectors, they always carry the stuff
away as soon as you turn your back on it.

You can find them easily by spotting stop-and-go traffic on any street.

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


[Haskell-cafe] Re: Haskell-cafe reply-to etiquette

2007-12-28 Thread Ben Franksen
Justin Bailey wrote:
 When I joined the haskell-cafe mailing list, I was surprised to see
 the reply-to header on each message was set to the sender of a given
 message to the list, rather than the list itself. That seemed counter
 to other mailing lists I had been subscribed to, but I didn't think
 too much about it.

I agree with the other replies, only want to add that I found news.gmane.org
an incredibly useful (and free) service for reading and posting to mailing
lists like this one. YMMV.

Cheers
ben

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


[Haskell-cafe] Unbuffered character IO under Windows XP?

2007-12-28 Thread Peter Schmitz
module Main(main) where
import System.IO

main = do
   b1 - hGetBuffering stdin
   print b1
   b2 - hGetBuffering stdout
   print b2

   -- not sure if these help, or are needed
   hSetBuffering stdin  NoBuffering
   hSetBuffering stdout NoBuffering

   b1 - hGetBuffering stdin
   print b1
   b2 - hGetBuffering stdout
   print b2

   putStr 0
   c - getChar   -- echoes during input by default
   putStr 1 -- want this output w/o hitting Enter
   hFlush stdout  -- adding this does not help
   putStrLn [c]

{--- Output:
E:\ghcTestghc --version
The Glorious Glasgow Haskell Compilation System, version 6.8.1

E:\ghcTestghc --make main
[1 of 1] Compiling Main ( main.hs, main.o )
Linking main.exe ...

E:\ghcTestmain
LineBuffering
LineBuffering
NoBuffering
NoBuffering
0a
1a

E:\ghcTest
- Question:
Is it possible to have unbuffered character IO under
Windows XP?

I would like to be able to type a single character and have
the processing and IO continue without having to hit Enter.

I.e., rather than this
(had to hit Enter after typing the 'a' in '0a'):
0a
1a

I would like to have this
(without having to hit Enter after typing the char):
0a1a

I have tried a few combinations of hSetBuffering and
put/get Str/Char functions, without success.

NOTE:
I need to run under Windows XP, non-administrator account.
This test was run using the normal XP shell cmd.exe.
Thanks much in advance.
-- Peter
}
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Doing some things right

2007-12-28 Thread Luke Palmer
On Dec 28, 2007 2:55 PM, Miguel Mitrofanov [EMAIL PROTECTED] wrote:
  I thought Lisp and Erlang were both infinitely more
  popular and better known.
 
  Certainly not infinitely.  Lisp isn't entirely functional, and while
  Erlang is an industrial success story, I think Haskell is seeing a
  wider range of application.

 Well, it seems for me that Erlang is much less functional than Lisp.
 It's totally OO, in fact.

OO is orthogonal to functional.  Erlang is pure functional, Lisp is a
bastard child...

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


[Haskell-cafe] Specializing classes with classes

2007-12-28 Thread alex
Hi, I am new to everything Haskell and am stumped on
an aspect of Type Classes.

I would like to do this:

class Foo t where
hi :: t - Bool

class Foo t = Bar t where
hi x = True

But using GHC 6.8.1 on PPC I get this error:

`hi' is not a (visible) method of class `Bar'

The actual problem is more like this:

class Num a = Alg a where
():: Mat m = m - a - a-- matrix
multiply

class Alg v = Vec v where
toRow, toColumn :: Mat m = v - m
fromRow, fromColumn :: Mat m = m - v

fromRow = fromColumn . transpose
toRow   = transpose . toColumn
   
() m v= fromColumn (m  (toColumn v))

class Alg m = Mat m where
transpose   :: m - m

(I hope that's readable...)

I'm having trouble finding what I need with Google,
and SOE doesn't really go into specifics.

Thanks for any help... Alex

















  Make the switch to the world's best email. Get the new Yahoo!7 Mail now. 
www.yahoo7.com.au/worldsbestemail


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


Re: [Haskell-cafe] Doing some things right

2007-12-28 Thread Jon Harrop
On Friday 28 December 2007 11:05:12 Andrew Coppin wrote:
 I thought Lisp and Erlang were both infinitely more 
 popular and better known. Followed by Clean and O'Camal.

According to the Debian and Ubuntu package popularity figures OCaml, Haskell 
and Erlang are the most popular general-purpose functional programming 
languages, followed by Lisp and Scheme:

http://flyingfrogblog.blogspot.com/2007/11/most-popular-functional-languages-on.html

OCaml, Haskell and Erlang are also growing much more rapidly than Lisp:

http://people.debian.org/~igloo/popcon-graphs/index.php?packages=ocaml-nox%2Cghc6%2Cerlang-base%2Csbcl%2Cclispshow_installed=onwant_legend=onwant_ticks=onfrom_date=to_date=hlght_date=date_fmt=%25Y-%25mbeenhere=1

However, both F# and Scala have the potential to dwarf all of these languages 
in the not-so-distant future. I believe F# will do so in 2008 but Scala will 
take 2-3 years because they have far fewer resources to develop essential 
tools like working IDE plug-ins.

 [I actually heard a number of people tell me that learning LISP would
 change my life forever because LISP has something called macros. I
 tried to learn it, and disliked it greatly. It's too messy. And what the
 heck is cdr ment to mean anyway? To me, LISP doesn't even seem all
 that different from normal languages (modulo weird syntax). Now
 Haskell... that's FUN!]

OCaml also has macros as well and, yes, forking the syntax of a language is a 
bad idea. I would have said that the metacircular evaluator was the most 
interesting aspect of Lisp/Scheme though, not macros.

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/products/?e
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Unbuffered character IO under Windows XP?

2007-12-28 Thread Ryan Ingram
I have this problem as well and would love to hear if there is an answer.

I think there are some windows terminal settings that the GHC runtime should
twiddle when you change the buffering state on stdin, but I don't know
exactly what is involved.

  -- ryan

On 12/28/07, Peter Schmitz [EMAIL PROTECTED] wrote:

 module Main(main) where
 import System.IO

 main = do
b1 - hGetBuffering stdin
print b1
b2 - hGetBuffering stdout
print b2

-- not sure if these help, or are needed
hSetBuffering stdin  NoBuffering
hSetBuffering stdout NoBuffering

b1 - hGetBuffering stdin
print b1
b2 - hGetBuffering stdout
print b2

putStr 0
c - getChar   -- echoes during input by default
putStr 1 -- want this output w/o hitting Enter
hFlush stdout  -- adding this does not help
putStrLn [c]

 {--- Output:
 E:\ghcTestghc --version
 The Glorious Glasgow Haskell Compilation System, version 6.8.1

 E:\ghcTestghc --make main
 [1 of 1] Compiling Main ( main.hs, main.o )
 Linking main.exe ...

 E:\ghcTestmain
 LineBuffering
 LineBuffering
 NoBuffering
 NoBuffering
 0a
 1a

 E:\ghcTest
 - Question:
 Is it possible to have unbuffered character IO under
 Windows XP?

 I would like to be able to type a single character and have
 the processing and IO continue without having to hit Enter.

 I.e., rather than this
 (had to hit Enter after typing the 'a' in '0a'):
 0a
 1a

 I would like to have this
 (without having to hit Enter after typing the char):
 0a1a

 I have tried a few combinations of hSetBuffering and
 put/get Str/Char functions, without success.

 NOTE:
 I need to run under Windows XP, non-administrator account.
 This test was run using the normal XP shell cmd.exe.
 Thanks much in advance.
 -- Peter
 }


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


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


Re: [Haskell-cafe] Specializing classes with classes

2007-12-28 Thread ajb

G'day all.

Quoting alex [EMAIL PROTECTED]:


I would like to do this:

class Foo t where
hi :: t - Bool

class Foo t = Bar t where
hi x = True


This is arguably one of the most requested features in Haskell.  The only
reason why it hasn't been implemented yet is that some of the corner cases
are a little subtle.

But this will get fixed, won't it, haskell-prime people?

What you'll have to do until then is something like this:

class Num a = Alg a where
():: Mat m = m - a - a

multByVec :: (Vec v, Mat m) = m - a - a
multByVec m v = fromColumn (m  toColumn v)

class Alg v = Vec v where
toRow, toColumn :: Mat m = v - m
fromRow, fromColumn :: Mat m = m - v

fromRow = fromColumn . transpose
toRow   = transpose . toColumn

class Alg m = Mat m where
transpose   :: m - m

class Alg SomeType where
() = multByVec

class Vec SomeType where
toRow = {- etc etc -}
{- and so on -}

Sorry, I wish there was a better answer.

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


Re: [Haskell-cafe] An interesting monad: Prompt

2007-12-28 Thread Thomas Hartman
Would you mind posting the code for Prompt used by

import Prompt

I tried using Prompt.lhs from your first post but it appears to be
incompatible with the guessing game program when I got tired of
reading the code and actually tried running it.

best, thomas.



2007/12/4, Ryan Ingram [EMAIL PROTECTED]:
 Ask and ye shall receive.  A simple guess-a-number game in MonadPrompt
 follows.

 But before I get to that, I have some comments:


 Serializing the state at arbitrary places is hard; the Prompt contains a
 continuation function so unless you have a way to serialize closures it
 seems like you lose.  But if you have safe points during the execution at
 which you know all relevant state is inside your game state, you can save
 there by serializing the state and providing a way to restart the
 computation at those safe points.

 I haven't looked at MACID at all; what's that?

  {-# LANGUAGE GADTs, RankNTypes #-}
  module Main where
  import Prompt
  import Control.Monad.State
  import System.Random (randomRIO)
  import System.IO
  import Control.Exception (assert)

 Minimalist functional references implementation.
 In particular, for this example, we skip the really interesting thing:
 composability.

 See http://luqui.org/blog/archives/2007/08/05/ for a real
 implementation.

  data FRef s a = FRef
{ frGet :: s - a
, frSet :: a - s - s
}

  fetch :: MonadState s m = FRef s a - m a
  fetch ref = get = return . frGet ref

  infix 1 =:
  infix 1 =:
  (=:) :: MonadState s m = FRef s a - a - m ()
  ref =: val = modify $ frSet ref val
  (=:) :: MonadState s m = FRef s a - m a - m ()
  ref =: act = act = modify . frSet ref
  update :: MonadState s m = FRef s a - (a - a) - m ()
  update ref f = fetch ref = \a - ref =: f a

 Interactions that a user can have with the game:

  data GuessP a where
 GetNumber :: GuessP Int
 Guess :: GuessP Int
 Print :: String - GuessP ()

 Game state.

 We could do this with a lot less state, but I'm trying to show what's
 possible here.  In fact, for this example it's probably easier to just
 thread the state through the program directly, but bigger games want real
 state, so I'm showing how to do that.

  data GuessS = GuessS
{ gsNumGuesses_ :: Int
, gsTargetNumber_ :: Int
}

  -- a real implementation wouldn't do it this way :)
  initialGameState :: GuessS
  initialGameState = GuessS undefined undefined

  gsNumGuesses, gsTargetNumber :: FRef GuessS Int
  gsNumGuesses   = FRef gsNumGuesses_   $ \a s - s { gsNumGuesses_   = a }
  gsTargetNumber = FRef gsTargetNumber_ $ \a s - s { gsTargetNumber_ = a }

 Game monad with some useful helper functions

  type Game = StateT GuessS (Prompt GuessP)

  gPrint :: String - Game ()
  gPrint = prompt . Print

  gPrintLn :: String - Game ()
  gPrintLn s = gPrint (s ++ \n)

 Implementation of the game:

  gameLoop :: Game Int
  gameLoop = do
 update gsNumGuesses (+1)
 guessNum - fetch gsNumGuesses
 gPrint (Guess # ++ show guessNum ++ :)
 guess - prompt Guess
 answer - fetch gsTargetNumber
 
 if guess == answer
   then do
 gPrintLn Right!
 return guessNum
   else do
 gPrintLn $ concat
 [ You guessed too 
 , if guess  answer then low else high
 , ! Try again.
 ]
 gameLoop

  game :: Game ()
  game = do
 gsNumGuesses =: 0
 gsTargetNumber =: prompt GetNumber
 gPrintLn I'm thinking of a number.  Try to guess it!
 numGuesses - gameLoop
 gPrintLn (It took you  ++ show numGuesses ++  guesses!)

 Simple unwrapper for StateT that launches the game.

  runGame :: Monad m = (forall a. GuessP a - m a) - m ()
  runGame f = runPromptM f (evalStateT game initialGameState)

 Here is the magic function for interacting with the player in IO.  Exercise
 for the reader: make this more robust.

  gameIOPrompt :: GuessP a - IO a
  gameIOPrompt GetNumber = randomRIO (1, 100)
  gameIOPrompt (Print s) = putStr s
  gameIOPrompt Guess = fmap read getLine

 If you wanted to add undo, all you have to do is save off the current Prompt
 in the middle of runPromptM; you can return to the old state at any time.

  gameIO :: IO ()
  gameIO = do
  hSetBuffering stdout NoBuffering
  runGame gameIOPrompt

 Here's a scripted version.

  type GameScript = State [Int]
 
  scriptPrompt :: Int - GuessP a - GameScript a
  scriptPrompt n GetNumber = return n
  scriptPrompt _ (Print _) = return ()
  scriptPrompt _ Guess = do
  (x:xs) - get -- fails if script runs out of answers
  put xs
  return x
 
  scriptTarget :: Int
  scriptTarget = 23
  scriptGuesses :: [Int]
  scriptGuesses = [50, 25, 12, 19, 22, 24, 23]

 gameScript is True if the game ran to completion successfully, and False or
 bottom otherwise.
 Try adding or removing numbers from scriptGuesses above and re-running the
 program.

  gameScript :: Bool
  gameScript = null $ execState (runGame (scriptPrompt scriptTarget))
 scriptGuesses


Re: [Haskell-cafe] Specializing classes with classes

2007-12-28 Thread alex
I see..

(Presumably you meant instance Alg Sometype,
instance Vec Sometype etc.)

I have got it working now, and it looks like:
1) I can't specialise superclass methods with other
class methods, within the class hierarchy, and
2) I have to instantiate each superclass individually,
for any type.

...which is consistent with what you were saying.
Thanks for clearing that up.

Now I know what they meant what they meant by leave
your OO at the door.


--- [EMAIL PROTECTED] wrote:

...

 What you'll have to do until then is something like
 this:
 
  class Num a = Alg a where
  ():: Mat m = m - a - a
 
  multByVec :: (Vec v, Mat m) = m - a - a
  multByVec m v = fromColumn (m  toColumn v)
 
  class Alg v  = Vec v where
  toRow, toColumn :: Mat m = v - m
  fromRow, fromColumn :: Mat m = m - v
 
  fromRow = fromColumn . transpose
  toRow   = transpose . toColumn
 
  class Alg m = Mat m where
  transpose   :: m - m
 
  class Alg SomeType where
  () = multByVec
 
  class Vec SomeType where
  toRow = {- etc etc -}
  {- and so on -}
 
 Sorry, I wish there was a better answer.
 
 Cheers,
 Andrew Bromage
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe
 



  Make the switch to the world's best email. Get the new Yahoo!7 Mail now. 
www.yahoo7.com.au/worldsbestemail


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


  1   2   >