PROTECTED]
Sent: Tuesday, July 31, 2007 5:09 PM
To: Bryan Burgers
Cc: peterv; haskell-cafe@haskell.org
Subject: Re: [Haskell-cafe] Newbie question about automatic memoization
Bryan Burgers wrote:
On 7/30/07, peterv [EMAIL PROTECTED] wrote:
Does Haskell support any form of automatic
Donald Bruce Stewart wrote:
Yeah, there's some known low level issues in the code generator
regarding heap and stack checks inside loops, and the use of registers
on x86.
But note this updated paper,
http://www.cse.unsw.edu.au/~chak/papers/CLPKM07.html
Add another core to your machine and
Donald:
Yeah, there's some known low level issues in the code generator
regarding heap and stack checks inside loops, and the use of registers
on x86.
But note this updated paper,
http://www.cse.unsw.edu.au/~chak/papers/CLPKM07.html
Add another core to your machine and it is no longer 4x
bf3:
Donald:
Yeah, there's some known low level issues in the code generator
regarding heap and stack checks inside loops, and the use of registers
on x86.
But note this updated paper,
http://www.cse.unsw.edu.au/~chak/papers/CLPKM07.html
Add another core to your machine and it is no
Donald Bruce Stewart wrote:
bf3:
Maybe this is yet another newbie stupid question, but do you mean that
GHC does automatic multi-threading? (Haskell seems very suitable for
that) Otherwise adding an extra core does not really help does it?
No, though that would be nice! You do have to
andrewcoppin:
Donald Bruce Stewart wrote:
bf3:
Maybe this is yet another newbie stupid question, but do you mean that
GHC does automatic multi-threading? (Haskell seems very suitable for
that) Otherwise adding an extra core does not really help does it?
No, though that would be nice!
Add another core to your machine and it is no longer 4x slower :)
Add 15 more cores and its really no longer 4x slower :
Maybe this is yet another newbie stupid question, but do you mean that
GHC does automatic multi-threading? (Haskell seems very suitable for
No, though that would be nice!
Am Freitag, 13. Juli 2007 15:03 schrieb peterv:
You see, in C++ I can write:
[snip]
So basically a wrapper around a fixed-size array of any length.
Implementations of (+), (-), dot, length, normalize, etc... then work on
vectors of any size, without the overhead of storing the size, and
Hello Donald,
Saturday, July 14, 2007, 6:01:21 AM, you wrote:
don't forget that laziness by itself makes programs an orders of
magnitude slower :)
Or orders of magnitude faster, depending on your data structure. :)
compared to naive implementation - yes, it's possible. compared to
handmade
]
Sent: Friday, July 13, 2007 6:43 PM
To: peterv
Cc: 'Lukas Mai'; haskell-cafe@haskell.org
Subject: Re[2]: [Haskell-cafe] Newbie question about tuples
Hello peterv,
Friday, July 13, 2007, 5:03:00 PM, you wrote:
think the latest compilers are much better). Now when implementing
something
like
Lukas Mai wrote:
You may be interested in
http://okmij.org/ftp/Haskell/number-parameterized-types.html
Thanks for that! It's all fascinating stuff...
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
Thanks Bulat, but now you scattered my hopes that GHC would magically do all
these optimizations for me ;-)
I must say that although the performance of Haskell is not really a concern to
me, I was a bit disappointed that even with all the tricks of the state monad,
unboxing, and
bf3:
Thanks Bulat, but now you scattered my hopes that GHC would magically do all
these optimizations for me ;-)
I must say that although the performance of Haskell is not really a concern
to me, I was a bit disappointed that even with all the tricks of the state
monad, unboxing, and
Am Donnerstag, 12. Juli 2007 20:14 schrieb Andrew Coppin:
The only thing the libraries provide, as far as I can tell, is the fact
that tuples are all Functors. (In other words, you can apply some
function to all the elements to get a new tuple.) I think that's about
it. I doubt you can use
://ubiety.uwaterloo.ca/~tveldhui/papers/Expression-Templates/exprtmpl.ht
ml... Well at least I hope so :)
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Lukas Mai
Sent: Friday, July 13, 2007 09:20
To: haskell-cafe@haskell.org
Subject: Re: [Haskell-cafe] Newbie question
On Friday 13 July 2007, peterv wrote:
I'm beginning to see that my old implementation in C++ clutters my Haskell
design.
You see, in C++ I can write:
// A vector is an array of fixed-length N and elements of type T
templatetypename T, int N struct Vector
{
T Element[N];
friend T
* possible?
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Jonathan Cast
Sent: Friday, July 13, 2007 16:21
To: haskell-cafe@haskell.org
Subject: Re: [Haskell-cafe] Newbie question about tuples
On Friday 13 July 2007, peterv wrote:
I'm beginning to see
peterv wrote:
with guaranteed termination, of course
Just out of curiosity (not Haskell related): I always get confused when
people speak about guaranteed termination; what about the halting problem?
In which context can one check for guaranteed termination, as the halting
problem says it's
Hello peterv,
Friday, July 13, 2007, 5:03:00 PM, you wrote:
think the latest compilers are much better). Now when implementing something
like this in Haskell, I would guess that its laziness would allow to
interleave many of the math operations, reordering them to be as optimal
as possible,
PROTECTED]
Sent: Friday, July 13, 2007 6:43 PM
To: peterv
Cc: 'Lukas Mai'; haskell-cafe@haskell.org
Subject: Re[2]: [Haskell-cafe] Newbie question about tuples
Hello peterv,
Friday, July 13, 2007, 5:03:00 PM, you wrote:
think the latest compilers are much better). Now when implementing
Lukas Mai wrote:
Am Donnerstag, 12. Juli 2007 20:14 schrieb Andrew Coppin:
The only thing the libraries provide, as far as I can tell, is the fact
that tuples are all Functors. (In other words, you can apply some
function to all the elements to get a new tuple.) I think that's about
it. I
peterv wrote:
with guaranteed termination, of course
Just out of curiosity (not Haskell related): I always get confused when
people speak about guaranteed termination; what about the halting problem?
In which context can one check for guaranteed termination, as the halting
problem says
Andrew Coppin wrote:
Lukas Mai wrote:
Am Donnerstag, 12. Juli 2007 20:14 schrieb Andrew Coppin:
The only thing the libraries provide, as far as I can tell, is the fact
that tuples are all Functors. (In other words, you can apply some
function to all the elements to get a new tuple.) I think
bulat.ziganshin:
Hello peterv,
Friday, July 13, 2007, 5:03:00 PM, you wrote:
think the latest compilers are much better). Now when implementing something
like this in Haskell, I would guess that its laziness would allow to
interleave many of the math operations, reordering them to be
Hi,
I have a couple of questions about tuples.
Q1) Is it possible to treat a tuple of N elements in a generic way? So
instead of writing functions like lift1 e1, lift2 (e1,e2), lift3 (e1,e2,e3)
just one function liftN that works on tuples of any length?
Q2) (Maybe related to Q1) Can I convert
Hi Peter,
2007/7/12, peterv [EMAIL PROTECTED]:
Q1) Is it possible to treat a tuple of N elements in a generic way? So
instead of writing functions like lift1 e1, lift2 (e1,e2), lift3 (e1,e2,e3)
just one function liftN that works on tuples of any length?
Q2) (Maybe related to Q1) Can I convert
peterv wrote:
Hi,
I have a couple of questions about tuples.
Q1) Is it possible to treat a tuple of N elements in a generic way? So
instead of writing functions like lift1 e1, lift2 (e1,e2), lift3 (e1,e2,e3)
just one function liftN that works on tuples of any length?
The only thing the
On Thu, 12 Jul 2007, Andrew Coppin wrote:
peterv wrote:
Q3) Suppose I want to declare an instance of Num on all tuple types having
(Num instances) as elements; is this possible?
I tried
instance Num a = Num (a,a) where .
but this fails
I also tried
peterv wrote:
Hi,
I have a couple of questions about tuples.
Q1) Is it possible to treat a tuple of N elements in a generic way? So
instead of writing functions like lift1 e1, lift2 (e1,e2), lift3
(e1,e2,e3) just one function liftN that works on tuples of any length?
If you have instances
I'm trying to get the SOE graphics library to compile for Win32 using the
latest libraries.
I fixed a couple of imports, but in the file GraphicsTypes.hs, the functions
toInt/fromInt are used, which are now obsolete:
type Dimension = Int
toDimension:: Win32.INT - Dimension
On Thu, Jun 28, 2007 at 09:16:37PM +0200, peterv wrote:
I'm trying to get the SOE graphics library to compile for Win32 using the
latest libraries.
I fixed a couple of imports, but in the file GraphicsTypes.hs, the functions
toInt/fromInt are used, which are now obsolete:
type Dimension =
toInt = id
fromInt = id
?
On 28 jun 2007, at 21.16, peterv wrote:
I’m trying to get the SOE graphics library to compile for Win32
using the latest libraries.
I fixed a couple of imports, but in the file GraphicsTypes.hs, the
functions toInt/fromInt are used, which are now obsolete:
On Mon, Jun 04, 2007 at 05:42:35PM +0300, Juozas Gaigalas wrote:
Hello,
I am a somewhat experienced programmer and a complete Haskell newbie, so I
hope this is the correct ML for my question.
I have decided to learn Haskell and started with Graham Hutton's book.
Everything was going
Hello,
I am a somewhat experienced programmer and a complete Haskell newbie, so I
hope this is the correct ML for my question.
I have decided to learn Haskell and started with Graham Hutton's book.
Everything was going nicely until section 8.4, on sequencing functional
parsers. I am trying to
On 6/4/07, Juozas Gaigalas [EMAIL PROTECTED] wrote:
Hello,
I am a somewhat experienced programmer and a complete Haskell newbie, so I
hope this is the correct ML for my question.
I have decided to learn Haskell and started with Graham Hutton's book.
Everything was going nicely until section
On 04/06/07, Alfonso Acosta [EMAIL PROTECTED] wrote:
Hugs is probably complaining because it identifies x - item (which
is not a simple expression) as the last element of do.
That was my first guess, too, but it's not the case, switch to a
monospaced font to see this.
Juozas, you could only
Hi Juozas,
-
type Parser a = String - [(a, String)]
return :: a - Parser a
return v = \inp - [(v, inp)]
failure :: Parser a
failure = \inp - []
item :: Parser Char
item = \inp - case inp of
[] - []
(x:xs) - [(x, xs)]
parse
David House wrote:
Juozas, you could only use do-notation if your Parser type were
declared an instance of the Haskell type-class Monad. Seeing as you
haven't done this, you have to stick to the de-sugared version
involving (=) and return:
Is this true? I thought do (like all sugar) was
Dan Weston wrote:
Is this true? I thought do (like all sugar) was desugared before
semantic analysis. So long as you have the right =, return, and fail
in scope, I would have thought the desugaring is oblivious to their
definition (and particularly ignorant of instancing of the Monad
On 22/04/07, Nikolay Metchev [EMAIL PROTECTED] wrote:
Hello guys,
I have decided to try and get back into Haskell recently. I have used it in
the past but have forgotten large chunks.
I am trying to express the logic of a particular card game. For this purpose
I need to be able to order cards in
Hello guys,
I have decided to try and get back into Haskell recently. I have used it in
the past but have forgotten large chunks.
I am trying to express the logic of a particular card game. For this purpose
I need to be able to order cards in various orders. At first I thought that
the Ord class
Nikolay Metchev wrote:
data Face = Ace | Two | Three | Four | Five | Six | Seven | Eight | Nine
| Ten | Jack | Queen | King deriving (Enum, Show, Eq)
listComparator :: (Eq a) = [a] - a - a - Ordering
listComparator xs a b = compare x y
where
x =
Hi, I am having difficulty compiling a program that uses a foreign
library. The readme says to first compile a C file:
: ghc mipFFI.c -c
mipFFI.c:1:0: lpkit.h: No such file or directory
Alright, that's not uncommon. gcc confirms
: gcc mipFFI.c
mipFFI.c:1: lpkit.h: No such file or directory
Hi Seth,
On Fri, Mar 16, 2007 at 01:53:49PM -0500, Seth J. Fogarty wrote:
: ghc -i/home/sfogarty/lib/lp_solve_5.5 mipFFI.c
mipFFI.c:1:0: lpkit.h: No such file or directory
ghc -I/home/sfogarty/lib/lp_solve_5.5 mipFFI.c
should work. If not, add -v to the commandline to see what it is
Hi all!
I'm just started learning denotational semantics and have a simple question.
Suppose, we have simple language L (e.g. some form of lambda-calculus)
and have a semantic function: E : Term_L - Value.
Now, suppose, we extended our language with some additional side-effects
(e.g. state
I'm still getting my head around this myself, but I know a few
references that might help (maybe not directly, but they're in the
ballpark).
1 I believe the phrase natural lifting or naturality of liftings
is what you're after when you attempt to compare a monad and a bigger
monad that includes
[my mail program hiccuped and chopped my message, sorry]
2 Another example that helped me when getting a feel for reasoning
about monadic code (which is the basis of what we're doing here) was
William Harrison's Proof Abstraction for Imperative Languages. It
uses monads and some of the notions
Hi,
I'm reading the Haskell school of expression by Paul Hudok. Great book.
However I would like some feedback about a solution to an exercise
The problem is quite simple :
define f1 and f2 (using higher order functions ) such that
f1 (f2 (*) [1..4]) 5 = [5,10,15,20]
I have come up with the
On 30/12/2006, at 1:33 PM, Pieter Laeremans wrote:
Hi,
I'm reading the Haskell school of expression by Paul Hudok. Great
book.
Hudak. And I concur, a great book.
However I would like some feedback about a solution to an exercise
The problem is quite simple :
define f1 and f2 (using
o To output anything, I need to do 'do'.
If you only have one action, you can omit do, e.g.
main = do { putStrLn Hello, World! }
is identical (after de-sguaring) to
main = putStrLn Hello, World!
Essentially, you are correct; to output anything (i.e. to perform I/O
by side effect) your
Hello Taro,
Tuesday, June 20, 2006, 9:32:51 AM, you wrote:
o To output anything, I need to do 'do'.
no, you should perform something having IO ... return type. do is
just a syntax way to join several IO ... actions into one action
having this type. i plan to write i/o and monads for beginners
2006/6/20, Taro Ikai [EMAIL PROTECTED]:
Sebastian,
Thanks for your help. I learned two things:
o show is not an action, but a function. Using it in the interactive
mode of GHCI was making me confused.
hi,
in ghci, if I want to see the result of an IO action, I do this
ghci x - myIOAction
Here's a code fragment I have from working with Hal Daume's Yet Another
Haskell Tutorial. I cannot figure out how to iterate over the result
from askForNumbers that returns IO [Integer], and print them.
The - operator seems to take IO off of the results from actions like
getContents, which
On 6/20/06, Taro Ikai [EMAIL PROTECTED] wrote:
Here's a code fragment I have from working with Hal Daume's Yet Another
Haskell Tutorial. I cannot figure out how to iterate over the result
from askForNumbers that returns IO [Integer], and print them.
The - operator seems to take IO off of the
Sebastian,
Thanks for your help. I learned two things:
o show is not an action, but a function. Using it in the interactive
mode of GHCI was making me confused.
o To output anything, I need to do 'do'.
-Taro
Sebastian Sylvan wrote:
On 6/20/06, Taro Ikai [EMAIL PROTECTED] wrote:
Here's a
most probably yes. I had the exact same question for:
module Factors
where
import Prelude
divides x y = (mod x y == 0)
factors x = filter (divides x) [1..x]
nonTrivialFactors x = filter (\y - y /= 1 y /= x)
[1..x]
isEmpty [] = True
isEmpty _ = False
-- isPrime = isEmpty .
Hi,
Newbie question. Given the inferred type for square,
the
inferred types for quad1, quad2 and quad3 are what I
would
expect. Is there a straightforward explanation (i.e.
one
that a newbie would understand) as to why the inferred
type
for quad4 is less general?
Regards,
dl
-- GHC
I think this is the monomorphism restriction, you can see more details
on the web page:
http://www.haskell.org/hawiki/MonomorphismRestriction
On 3/30/06, David Laffin [EMAIL PROTECTED] wrote:
Hi,
Newbie question. Given the inferred type for square,
the
inferred types for quad1, quad2 and
Hello,
For the purpose of familiarizing myself with Haskell, and also because I
love Haskell :),
I am trying to re-make a script that I made in Python that sends a
request to a server and extracts the list of email addresses from a
Mailman web-page by using an XML Parser on the page's HTML that
You can access IO values only from within do blocks (see any tutorial,
previous posts or google).
It looks like this then:
do=
myvalue - functionwhichreturnsIOValue
dosomethingwith myvalue
Due to monads you don't have to leave the IO monad this way.
Oh. Have to go now.
do is translated into
Peter [EMAIL PROTECTED] writes:
So, How am I supposed to get the value of an IO Monad, such as IO
String, without returning an IO Monad?
Short answer: you don't. IO is a one way street.
Build your application top down in the IO monad (starting with
'main'), and bottom up with pure code,
On 2/17/06, Peter [EMAIL PROTECTED] wrote:
Hello,
For the purpose of familiarizing myself with Haskell, and also because I
love Haskell :),
I am trying to re-make a script that I made in Python that sends a
request to a server and extracts the list of email addresses from a
Mailman web-page
Hi,
Am Freitag, 17. Februar 2006 14:42 schrieb Peter:
Hello,
For the purpose of familiarizing myself with Haskell, and also because I
love Haskell :),
very good!
I am trying to re-make a script that I made in Python that sends a
request to a server and extracts the list of email addresses
Peter wrote:
So, How am I supposed to get the value of an IO Monad, such as IO
String, without returning an IO Monad?
You read correctly, this is impossible. You already got some valid
answers, and here's another variant that preserves most of the nice
guarded expressions:
recv_headers' ::
Hi,
Apart from the other posts, you might also want to read
http://www.haskell.org/hawiki/IntroductionToIO which is a quick intro
to the way IO is handled in Haskell and
http://www.haskell.org/hawiki/UsingIo which covers similar ground, but
which also goes into a number of other common questions.
Thanks all of your for your time and your interesting examples. Now I
can see that my problem is parsing a String. I am new in Haskell, so, I
start to study parsing and how to create a parser from beginning.
I start with an example from the book as follows:
%The parser item fails if the input is
Huong Nguyen [EMAIL PROTECTED] writes:
newtype Parser a = Parser(String - [(a, String)])
[...]
parse :: Parser a - String - [(a, String)]
parse p cs = p cs
\end{code}
Try this instead:
parse (Parser p) cs = p cs
(You forgot to deconstruct! :) )
Right, forgot about seq there, but the point still holds that there
are a very limited number of functions of that type, and in
particular, the functions can't decide what to do based on the type
parameter 'a'.
- Cale
On 14 Oct 2005 05:49:27 -, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
On Fri, Oct 14, 2005 at 03:17:12AM -0400, Cale Gibbard wrote:
Right, forgot about seq there, but the point still holds that there
are a very limited number of functions of that type, and in
particular, the functions can't decide what to do based on the type
parameter 'a'.
actually, without
Cale Gibbard wrote:
As an example of this sort of thing, I know that there are only 4
values of type a - Bool (without the class context). They are the
constant functions (\x - True), (\x - False), and two kinds of
failure (\x - _|_), and _|_, where _|_ is pronounced bottom and
represents
On 10/13/05, Huong Nguyen [EMAIL PROTECTED] wrote:
Hi all,
I want to write a small functionto test whether an input is a String or not.
For example,
isString::(Show a) =a -Bool
This function will return True if the input is a string and return False if
not
Any of you have idea about
So this is essentially a parsing problem. You want a user to be able
input a string and have it interpreted as an appropriate data value. I
think you may want to look at the Parsec library
(http://www.cs.uu.nl/~daan/parsec.html). I don't think the direction
you are heading will get the
Hi Huong,
attached you find a small program for parsing values of various (data)
types. It uses a generalized algebraic data type for representing types
and a universal data type for representing values. The parser itself is
rather simple-minded: it builds on Haskell's ReadS type.
I don't know
Hi all,
I want to write a small functionto test whether an input is a String or not. For example,
isString::(Show a) =a -Bool
This function will return True if the input is a string and return False if not
Any of you have idea about that? Thanks in advance
isString::(Show a) =a -Bool
This function will return True if the input is a string and return False if
not
This is not particularly nicely - you certainly can't write it as
simple as the 'isString' function, and it will probably require type
classes etc, quite possibly with haskell extensions.
In GHC you can do this:
import Data.Typeable
isString :: (Typeable a) = a - Bool
isString x = typeOf x == typeOf (undefined::String)
Why do you want this? It's not the kind of operation one does very
often in Haskell.
Huong Nguyen wrote:
Hi all,
I want to write a small functionto
--- Cale Gibbard [EMAIL PROTECTED] wrote:
As an example of this sort
of thing, I know that there are only 4
values of type a - Bool (without
the class context). They are the
constant functions (\x - True), (\x -
False), and two kinds of
failure (\x - _|_), and _|_, where _|_ is pronounced
Hello everybody,
This seems so simple question, but I did not find the solution.
HaXML is installed. Do you know how I can run HaXML in Linux/Unix (which command I should write). Thank you.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
Huong Nguyen [EMAIL PROTECTED] writes:
HaXML is installed. Do you know how I can run HaXML in Linux/Unix (which
command I should write). Thank you.
That depends what you want to do with it.
HaXml is a library of modules for processing XML, so one answer to your
question is just write some
Hi everyone,
I think this is a totally newbie question as i am a complete novice
to Haskell. I am trying to write down a few programs using GHC in order
to get used with the language. I am having some problems with a piece of
code (that is supposed to return a list of lines from a text
On 8/12/05, David Roundy [EMAIL PROTECTED] wrote:
On Fri, Aug 12, 2005 at 09:17:32AM -0300, Andr Vargas Abs da Cruz wrote:
readDataFromFile filename = do
bracket (openFile filename ReadMode) hClose
(\h - do contents - hGetContents h
return (lines
On Fri, Aug 12, 2005 at 02:54:03PM +0200, Lemmih wrote:
On 8/12/05, David Roundy [EMAIL PROTECTED] wrote:
On Fri, Aug 12, 2005 at 09:17:32AM -0300, Andr Vargas Abs da Cruz wrote:
readDataFromFile filename = do
bracket (openFile filename ReadMode) hClose
(\h - do contents
André Vargas Abs da Cruz wrote:
I think this is a totally newbie question as i am a complete novice
to Haskell. I am trying to write down a few programs using GHC in order
to get used with the language. I am having some problems with a piece of
code (that is supposed to return a list
Thank you all for your answers. I'll try to be more careful with lazy
evaluations while doing IO operations from now on.
Best regards
André
On Fri, Aug 12, 2005 at 02:54:03PM +0200, Lemmih wrote:
On 8/12/05, David Roundy [EMAIL PROTECTED] wrote:
On Fri, Aug 12, 2005 at 09:17:32AM
This question comes up often, and there are lots of ways to answer it.
Not too long ago, I posted a simplistic (but not terribly practical)
solution, writing a strict version of readFile in terms of hGetChar,
to which Simon Marlow replied with an actually pratical implementation
which allocates
Hello everybody,
Now I am writing a module to handles messages of a system. The
messages are stored in a file. The content of each line of the file
likes this:
1001 001 Error message 1
1001 002 Error message 2
1002
Here's how I wrote it:
- beginning of file
import IO
-- turn a line of the text file into a pair consisting of
-- the message triple and the message string
-- slight bug: will contract multiple spaces in the message string
-- This could be rewritten to avoid this problem, but couldn't make
We're being clever and returning from IO not a Char, but a MyMonad Char
(mimp). Then, we run that, which either produces the answer we wanted,
or throws an error in MyMonad.
Thanks. That did the trick! :-)
Regards
However, it's still rather cumbersome, so here's a function similar to
Hello!
I'm confused by the error handling in Haskell. I've written a program that
uses a combined monad of type:
type MyMonad a = ErrorT MyErrorType (StateT MyStateType IO) a
(MyErrorType is an instance of Error)
Therefore, to handle IO Errors inside of MyMonad I need to write:
foo :: MyMonad
On Sun, Jul 24, 2005 at 08:00:58PM +, Gerd M wrote:
Hello!
I'm confused by the error handling in Haskell. I've written a program that
uses a combined monad of type:
type MyMonad a = ErrorT MyErrorType (StateT MyStateType IO) a
(MyErrorType is an instance of Error)
Therefore, to handle
I'm working through The craft of functional programming , and I've
come to excercise 3.14: Give a function to return the average of
three integers.
My attempt at an answer is:
averageThree :: Int - Int - Int - Float
averageThree a b c = fromInt(a + b + c) / 3
but when I try to load this file I
The function fromInt is no longer around. Use fromIntegral instead,
which works with Int and Integer.
On 4/28/05, Tim Rowe [EMAIL PROTECTED] wrote:
I'm working through The craft of functional programming , and I've
come to excercise 3.14: Give a function to return the average of
three
Sorry, I had to drop out of this thread for a few days...
Ben Rudiak-Gould wrote:
Paul Hudak wrote:
Note that instead of:
data Shape = Circle Float
| Square Float
the Haskell designers might have used the following syntax:
data Shape where
Circle :: Float - Shape
Ben Rudiak-Gould [EMAIL PROTECTED] writes:
In particular, your notation with type signatures makes it totally
unclear that Circle and Square have disjoint ranges; in fact it looks
like they have the same range.
:
The syntax that would have made the most sense to me would have been
Put the data declaration in a module, export the type, but
not the constructor you want to hide:
module Shape (Shape(Square), circle) where
Since we were talking about 'what can one do with a constructor as compared
with a function', it should be mentioned that this also has a
Brian Beckman wrote:
data Shape = Circle Float
| Square Float
I read this something along the lines of 'Shape' is a type constructor,
for use in other type-defining expressions, and 'Circle' and 'Sqare' are
its two data constructors, which should be used like functions of type
'Float -
Oh, I disagree with this point of view. Circle is certainly a value,
i.e. a full-fledged function, as Brian Beckman correctly surmised. The
Ben Rudiak-Gould wrote:
Brian Beckman wrote:
data Shape = Circle Float
| Square Float
I read this something along the
Paul Hudak wrote:
Oh, I disagree with this point of view. Circle is certainly a value,
i.e. a full-fledged function, as Brian Beckman correctly surmised.
Interesting. I don't claim that my viewpoint is the One True Path, but I
don't think it's wrong, either. I know you're interested in the
Keith Wansbrough wrote:
Indeed, they are functions. Another way of thinking about it is as an
initial algebra (technical term). What this means is this:
Shape is a set of values that contains
- the result of Circle x for all values x :: Float
- the result of Square x for all
On Mon, 1 Nov 2004, Ben Rudiak-Gould wrote:
Paul Hudak wrote:
Oh, I disagree with this point of view. Circle is certainly a value,
i.e. a full-fledged function, as Brian Beckman correctly surmised.
Interesting. I don't claim that my viewpoint is the One True Path, but I
don't think
101 - 200 of 209 matches
Mail list logo