On 28 Mar 2008, at 03:03, Ryan Ingram wrote:
Another way to defer the evaluation of the second argument of (-+)
is like this:
(-+) :: a - List a - List a
x -+ y = List(f) where
f 0 = x
f k = case y of List g - g (k-1)
This is exactly what the lazy pattern will do at compile-time.
On 28 Mar 2008, at 03:03, Ryan Ingram wrote:
Another way to defer the evaluation of the second argument of (-+)
is like this:
(-+) :: a - List a - List a
x -+ y = List(f) where
f 0 = x
f k = case y of List g - g (k-1)
This is exactly what the lazy pattern will do at compile-time. Does
On 28 Mar 2008, at 03:03, Ryan Ingram wrote:
Another way to defer the evaluation of the second argument of (-+)
is like this:
(-+) :: a - List a - List a
x -+ y = List(f) where
f 0 = x
f k = case y of List g - g (k-1)
This is exactly what the lazy pattern will do at compile-time. Does
I have fixed the problem now. In the last letter, with the Natural
class, I had not added
instance Num Natural where
(N x) - (N y) = N(x - y)
which the Ordinal class then in fact has one. Then it turns out that
it is merely the fact that show had some cases looking at the list
length
When experimenting with list index sets (i.e. lists more general than
provided by Haskell), I arrived at the problem that in the example
code below for example
h(list 6)
does not (in Hugs) write out the beginning of the list lazily. It
does work for
list 6
first (list 6)
rest (list
Hans Aberg wrote:
When experimenting with list index sets (i.e. lists more general than
provided by Haskell), I arrived at the problem that in the example code
below for example
h(list 6)
does not (in Hugs) write out the beginning of the list lazily. It does
work for
list 6
first (list
On Thu, Mar 27, 2008 at 2:18 PM, Claude Heiland-Allen
The combination of (-+) and h is too strict, this modification works:
(-+) :: a - List a - List a
x -+ ~(List y) = List(f) where -- lazy pattern match
f 0 = x
f k = y(k-1)
More to the point, if List is declared as:
On 27 Mar 2008, at 15:18, Claude Heiland-Allen wrote:
The combination of (-+) and h is too strict, this modification works:
(-+) :: a - List a - List a
x -+ ~(List y) = List(f) where -- lazy pattern match
f 0 = x
f k = y(k-1)
Thank you for the fast response. Yes, that might be what I
On 27 Mar 2008, at 15:32, Luke Palmer wrote:
More to the point, if List is declared as:
newtype List a = List (Integer - a)
Instead of with data, it also works.
The problem, as was stated, was that -+ is too strict. That is,
without the ~ there, -+ evaluates its right argument to make
Hmmm, seems like your (-+) is not lazy enough.
Since pattern matching is strict by default, you have
anything -+ (_|_) = (_|_)
Therefore, the function, which is constantly (_|_), is a fixed point
for the equation defining h. In other words, if you define
h' x = undefined
then you have
h'
On 27 Mar 2008, at 15:58, Miguel Mitrofanov wrote:
Hmmm, seems like your (-+) is not lazy enough.
...
You can fix it by defining (-+) as
x -+ ~(List y) = ...
Yes, this has been pointed out...
Since pattern matching is strict by default, you have
anything -+ (_|_) = (_|_)
Therefore,
On 27 Mar 2008, at 17:51, Luke Palmer wrote:
By your naming, am I correct in assuming that you're implementing
transfinite lists?
If so, cool!
Yes, it is an old idea I brought up now. If list length is written
also for infinite lists, then concatenated lists get indexed by the
sum of
On 27 Mar 2008, at 17:51, Luke Palmer wrote:
A more standard way to do this would be:
data List a = List (Ordinal - a) Ordinal
I used
data List a = Empty | (Ordinal-a) :+ Ordinal
which might then be simplified by dropping Empty.
Hans Aberg
Another way to defer the evaluation of the second argument of (-+) is like this:
(-+) :: a - List a - List a
x -+ y = List(f) where
f 0 = x
f k = case y of List g - g (k-1)
This is exactly what the lazy pattern will do at compile-time. Does
this give you a better understanding of how lazy
hiya
I was wondering how I would get the second function do recursively do the
function for poolNews xs tried that and it fails.
Ryan
--Give wins, draws a rating.
poolNews :: Result - PoolNews - PoolNews
poolNews (a,b,c,d,e) (home,away,goaless,scoredraw)
| c d =
Looks to me like you want:
poolNewsB = foldr poolNews (0,0,0,0)
On Nov 10, 2007 11:54 AM, Ryan Bloor [EMAIL PROTECTED] wrote:
hiya
I was wondering how I would get the second function do recursively do the
function for poolNews xs tried that and it fails.
Ryan
--Give wins, draws
On Nov 10, 2007 11:54 AM, Ryan Bloor [EMAIL PROTECTED] wrote:
hiya
I was wondering how I would get the second function do recursively do the
function for poolNews xs tried that and it fails.
Ryan
--Give wins, draws a rating.
poolNews :: Result
*-* PoolNews *-* PoolNews
Does the following code increase the level of recursion
once for each input line or is the recursive construct
converted to an iteration?
Thanks,
Dave Feustel
main :: IO ()
main = do
line - getLine
processIt line
main
processIt :: String - IO ()
processIt s = do
print (length s)
On 3/6/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
Does the following code increase the level of recursion
once for each input line or is the recursive construct
converted to an iteration?
Thanks,
Dave Feustel
main :: IO ()
main = do
line - getLine
processIt line
main
processIt ::
Bryan,
The code here does not take advantage of laziness, which is probably what you
want to do, as it is much cleaner to look at and more Haskell like. In
answer to your question it is tail recursive, and strict, which means that in
some compilers, with some optimization flags (i.e. GHC)
On 3/6/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
Does the following code increase the level of recursion
once for each input line or is the recursive construct
converted to an iteration?
As was pointed out, tail recursion in Haskell isn't straightforward.
The answer may also depend on
For absorbing the functional style of programming (which is what you really
should be working on at this point),
For functional style and the reasoning attitude associated with lazy
functional programming, the following book is a good introduction:
@Book{Bird-2000,
author = {Richard
P. R. Stanley:
is there another general pattern for mylen, head or tail?
mylen [] = 0
mylen (x:xs) = 1 + mylen (xs)
head [] = error what head?
head (x:xs) = x
tail [] = error no tail
tail (x:xs)= xs
Benjamin Franksen:
Another very common 'pattern' is to factor the recursion into a
Brandon, Chris, Don,
gentlemen,
Thank you all for your swift and well-written answers.
I should point out that I'm coming to functional programming with a
strong background in programming in C and C-type languages. I am also
very new to the whole philosophy of functional programming. Hence my
On Feb 18, 2007, at 21:26 , P. R. Stanley wrote:
mylen (x:y) = 1 + mylen y
The base case, if that is the right terminology, stipulates that
the recursion ends with an empty list and returns 0. Simple though
one question - why does mylen require the parentheses even when it
is evaluating
P. R. Stanley wrote:
Brandon, Chris, Don,
gentlemen,
Thank you all for your swift and well-written answers.
I should point out that I'm coming to functional programming with a
strong background in programming in C and C-type languages. I am also
very new to the whole philosophy of functional
On Feb 18, 2007, at 21:44 , Michael Vanier wrote:
I think what you're asking here is why you need the parens around
(x:y) in the second case. Function application doesn't use
parentheses
Function application never applies to pattern matching.
The usual answer to this is category theory
Brandon S. Allbery KF8NH wrote:
On Feb 18, 2007, at 21:44 , Michael Vanier wrote:
I think what you're asking here is why you need the parens around
(x:y) in the second case. Function application doesn't use parentheses
Function application never applies to pattern matching.
You're
Chaps,
is there another general pattern for mylen, head or tail?
mylen [] = 0
mylen (x:xs) = 1 + mylen (xs)
head [] = error what head?
head (x:xs) = x
tail [] = error no tail
tail (x:xs)= xs
This pattern matching reminds me of a module on formal spec I studied
at college.
What are the
P. R. Stanley wrote:
What are the pre-requisites for Lambda calculus?
Thanks
Paul
Learning lambda calculus requires no prerequisites other than the ability to
think clearly. However, don't think that you need to understand all about
lambda calculus in order to learn Haskell. It's more
On Feb 18, 2007, at 22:22 , P. R. Stanley wrote:
is there another general pattern for mylen, head or tail?
Those are basically it, aside from optionally replacing the unused
variables with _.
What are the pre-requisites for Lambda calculus?
Lambda calculus isn't related to what's
Michael Vanier wrote:
P. R. Stanley wrote:
What are the pre-requisites for Lambda calculus?
Thanks
Paul
Learning lambda calculus requires no prerequisites other than the
ability to think clearly. However, don't think that you need to
understand all about lambda calculus in order to learn
Hi
I understand the basic principle of recursion but have difficulty
with the following:
-- a recursive function
-- for calculating the length of lists
myLen [] = 0
myLen (x:xs) = 1 + myLen xs
What's happening here?
Top marks for a comprehensive jargon-free explanation.
Thanks in advance
Paul
On Feb 17, 2007, at 21:32 , P. R. Stanley wrote:
Hi
I understand the basic principle of recursion but have difficulty
with the following:
-- a recursive function
-- for calculating the length of lists
myLen [] = 0
myLen (x:xs) = 1 + myLen xs
What's happening here?
This definition uses
prstanley:
Hi
I understand the basic principle of recursion but have difficulty
with the following:
-- a recursive function
-- for calculating the length of lists
myLen [] = 0
myLen (x:xs) = 1 + myLen xs
So this is a definition for the 'length' function on lists.
The list data structure
The definition of myLen says:
myLen [] = 0
The length for an empty list is zero
myLen (x:xs) = 1 + myLen xs
The length of a list containing x and some other stuff (xs) is 1 +
(the length of the other stuff).
So basically, if you've got a list [1,2,3], it will try to do this:
myLen
36 matches
Mail list logo