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
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
:: 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
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
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 ==
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
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)
...@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
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
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
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
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
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
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 =
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:
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
: 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
?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
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
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 =
] 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
:[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
class ShapeInterface shape where
area :: Num numberType = shape-numberType
data ShapeType = forall a. ShapeInterface a = ShapeType a
instance (Num a) = ShapeInterface (SquareType a)
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
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 =
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)
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.
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
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
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
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
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
32 matches
Mail list logo