[Haskell-cafe] Sol vingt simple problem in various languages and systems

2013-02-07 Thread Doaitse Swierstra
At https://gist.github.com/ckirkendall/2934374 you find solutions in many languages to a simple programming problem: the evaluation of an expression in an environment. I want to point your attention to the currently last three entries: - one using the UUAGC compiler to solve the problem

Re: [Haskell-cafe] Help to solve simple problem !

2009-11-10 Thread Ezra Lalonde
with it ? Thank you in advance ! -- View this message in context: http://old.nabble.com/Help-to-solve-simple-problem-%21-tp26249028p26292205.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell

Re: [Haskell-cafe] Help to solve simple problem !

2009-11-10 Thread Eduard Sergeev
:: Eq a = [a] - [(a, Int)] compress = map (head length) group -- View this message in context: http://old.nabble.com/Help-to-solve-simple-problem-%21-tp26249028p26294356.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com

Re: [Haskell-cafe] Simple program. Simple problem?

2009-10-12 Thread Peter Verswyvelen
On Mon, Oct 12, 2009 at 1:08 AM, Felipe Lessa felipe.le...@gmail.comwrote: On Mon, Oct 12, 2009 at 12:42:16AM +0200, Peter Verswyvelen wrote: btw I always find it amusing to play with interact and lazy IO: I always find it frightening to play with lazy IO :). yes, I guess that's why I like

[Haskell-cafe] Simple program. Simple problem?

2009-10-11 Thread michael rice
What is going wrong here? Michael === import System.Random coinToss :: StdGen - IO () coinToss gen = putStrLn What's your guess, heads or tails ('h' or 't')?    getChar    = \c - let (randInt, _) = randomR(0,1) gen :: (Int, StdGen)     in if c ==

Re: [Haskell-cafe] Simple program. Simple problem?

2009-10-11 Thread Peter Verswyvelen
It always helps to put a Debug.Trace.trace: in if trace (show (fromEnum c)) $ c == ((!!) ht randInt) then p What's your guess, heads or tails ('h' or 't')? h 104 You win! What's your guess, heads or tails ('h' or 't')? *10* You lose! What's your guess, heads or tails ('h' or

Re: [Haskell-cafe] Simple program. Simple problem?

2009-10-11 Thread Peter Verswyvelen
btw I always find it amusing to play with interact and lazy IO: guess :: [Char] - [String] - [String] guess (c:cs) ~(i:is) = What's your guess, heads or tails ('h' or 't')? : (if [c]==i then You win! else You lose!) : guess cs is main = do gen - getStdGen let rs = randomRs (0,1::Int)

Re: [Haskell-cafe] Simple program. Simple problem?

2009-10-11 Thread michael rice
...@gmail.com wrote: From: Peter Verswyvelen bugf...@gmail.com Subject: Re: [Haskell-cafe] Simple program. Simple problem? To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Sunday, October 11, 2009, 6:42 PM btw I always find it amusing to play with interact and lazy IO: guess :: [Char

Re: [Haskell-cafe] Simple program. Simple problem?

2009-10-11 Thread Felipe Lessa
On Mon, Oct 12, 2009 at 12:42:16AM +0200, Peter Verswyvelen wrote: btw I always find it amusing to play with interact and lazy IO: I always find it frightening to play with lazy IO :). -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe] Simple program. Simple problem?

2009-10-11 Thread michael rice
Lessa felipe.le...@gmail.com Subject: Re: [Haskell-cafe] Simple program. Simple problem? To: haskell-cafe@haskell.org Date: Sunday, October 11, 2009, 7:08 PM On Mon, Oct 12, 2009 at 12:42:16AM +0200, Peter Verswyvelen wrote: btw I always find it amusing to play with interact and lazy IO: I always

Re: [Haskell-cafe] Simple program. Simple problem?

2009-10-11 Thread michael rice
felipe.le...@gmail.com wrote: From: Felipe Lessa felipe.le...@gmail.com Subject: Re: [Haskell-cafe] Simple program. Simple problem? To: haskell-cafe@haskell.org Date: Sunday, October 11, 2009, 7:08 PM On Mon, Oct 12, 2009 at 12:42:16AM +0200, Peter Verswyvelen wrote: btw I always find it amusing

split (was Re: [Haskell-cafe] Simple program. Simple problem?)

2009-10-11 Thread Reid Barton
It seems that the definition of split in System.Random is not really satisfactory. Imagine a tree-like computation of the form f gen = {- some expression using b, g1, g2 -} where b = fst (random gen) :: Bool (gen1, gen2) = split gen g1 = f gen1 g2 = f gen2 Let's look

Re: split (was Re: [Haskell-cafe] Simple program. Simple problem?)

2009-10-11 Thread Reid Barton
On Sun, Oct 11, 2009 at 08:17:48PM -0400, Reid Barton wrote: It seems that the definition of split in System.Random is not really satisfactory. For the curious, the reason for the asymmetry between fst . split and snd . split is that the RNG states produced by mkStdGen have varying first

[Haskell-cafe] nice simple problem for someone struggling....

2007-12-21 Thread Nicholls, Mark
I'm just trying to pick up the basicsand I've managed to write this code...which remarkably works.. module Main where data SquareType = SquareConstructor Int class ShapeInterface shape where area :: shape-Int data ShapeType = forall a. ShapeInterface a =

Re: [Haskell-cafe] nice simple problem for someone struggling....

2007-12-21 Thread Jules Bean
Nicholls, Mark wrote: *instance* ShapeInterface SquareType *where* area (SquareConstructor sideLength) = sideLength * sideLength *data* SquareType a = Num a = SquareConstructor a Now you have changed your type from SquareType to SquareType a, you need to change the instance to:

RE: [Haskell-cafe] nice simple problem for someone struggling....

2007-12-21 Thread Nicholls, Mark
ReallyI'm sure I tried that...(as it seemed obvious) ... and it failedbut I'll have another go -Original Message- From: Jules Bean [mailto:[EMAIL PROTECTED] Sent: 21 December 2007 15:33 To: Nicholls, Mark Cc: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] nice simple

RE: [Haskell-cafe] nice simple problem for someone struggling....

2007-12-21 Thread Nicholls, Mark
: Jules Bean [mailto:[EMAIL PROTECTED] Sent: 21 December 2007 15:33 To: Nicholls, Mark Cc: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] nice simple problem for someone struggling Nicholls, Mark wrote: *instance* ShapeInterface SquareType *where* area (SquareConstructor sideLength

RE: [Haskell-cafe] nice simple problem for someone struggling....

2007-12-21 Thread Nicholls, Mark
?if notwhy not? 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

Re: [Haskell-cafe] nice simple problem for someone struggling....

2007-12-21 Thread David Menendez
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

Re: [Haskell-cafe] nice simple problem for someone struggling....

2007-12-21 Thread Brent Yorgey
class ShapeInterface shape where area :: shape-Int now looks dubiousI want it to be something like class ShapeInterface shape where area :: Num numberType = shape-Int ? Rather, I think you probably want class ShapeInterface shape where area :: Num numberType =

RE: [Haskell-cafe] nice simple problem for someone struggling....

2007-12-21 Thread Nicholls, Mark
] nice simple problem for someone struggling class ShapeInterface shape where area :: shape-Int now looks dubiousI want it to be something like class ShapeInterface shape where area :: Num numberType = shape-Int

RE: [Haskell-cafe] nice simple problem for someone struggling....

2007-12-21 Thread Nicholls, Mark
:[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

Re: [Haskell-cafe] nice simple problem for someone struggling....

2007-12-21 Thread Miguel Mitrofanov
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)

Re: [Haskell-cafe] nice simple problem for someone struggling....

2007-12-21 Thread David Menendez
On Dec 21, 2007 12:08 PM, Nicholls, Mark [EMAIL PROTECTED] wrote: I thought from Num numberType = SquareConstructor numberType We could deduce that (in English rather than get Haskell and FOL confusion) all values of SquareConstructor a….the type of a would have be be in class

Re: [Haskell-cafe] nice simple problem for someone struggling....

2007-12-21 Thread David Menendez
On Dec 21, 2007 12:47 PM, Nicholls, Mark [EMAIL PROTECTED] wrote: 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 =

Re: [Haskell-cafe] nice simple problem for someone struggling....

2007-12-21 Thread Jules Bean
David Menendez wrote: That's a reasonable thing to assume. It just happens that Haskell doesn't work that way. There's an asymmetry between constructing and pattern-matching, and it's one that many people have complained about. With GADTs turned on (-XGADTS in 6.8, -fglasgow-exts in 6.6)

Re: [Haskell-cafe] nice simple problem for someone struggling....

2007-12-21 Thread David Menendez
On Dec 21, 2007 2:38 PM, Jules Bean [EMAIL PROTECTED] wrote: David Menendez wrote: That's a reasonable thing to assume. It just happens that Haskell doesn't work that way. There's an asymmetry between constructing and pattern-matching, and it's one that many people have complained about.

Re: Simple problem from Hudak's SOE

2003-02-22 Thread Dean Herington
On Fri, 21 Feb 2003, M. Parker wrote: I'm a real newbie to Haskell, and I'm having trouble with a particular problem dealing with higher-order functions. Exercise 5.9 in Hudak's School of Expression asks us to write a function, makeChange, s.t. it makes change for a given amount using

A simple problem

2001-01-18 Thread Saswat Anand
class C a where fun :: a - Integer instance C Integer where fun x = x+ 1 with these definitons: fun 3 --gives error in Hugs fun (3::Integer) -- OK I am a building an embedded language, so don't want user to cast. Is there a solution? Thanks, Saswat

Re: A simple problem

2001-01-18 Thread Ashley Yakeley
At 2001-01-18 05:16, Saswat Anand wrote: class C a where fun :: a - Integer instance C Integer where fun x = x+ 1 with these definitons: fun 3 --gives error in Hugs fun (3::Integer) -- OK I am a building an embedded language, so don't want user to cast. Is there a solution? 3 is not

Re: A simple problem

2001-01-18 Thread Ashley Yakeley
At 2001-01-18 15:38, I wrote: 3 is not always an Integer. It's of type "(Num a) = a". Of course, it would be nice if 3 were an Integer, and Integer were a subtype of Real. I haven't come across a language that does this, where for instance 3.0 can be cast to Integer (because it is one) but

Re: A simple problem

2001-01-18 Thread William Lee Irwin III
At 2001-01-18 15:57, William Lee Irwin III wrote: class C a where fun :: a - Integer instance Integral a = C a where fun = toInteger . succ On Thu, Jan 18, 2001 at 04:04:01PM -0800, Ashley Yakeley wrote: Gives "syntax error in instance head (constructor expected)" at the