[Haskell-cafe] hiii

2006-12-27 Thread omit singh rathore
  
 Send free SMS to your Friends on Mobile from your Yahoo! Messenger. Download 
Now! http://messenger.yahoo.com/download.php___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] SYB and/or HList for XML, deserialization and collections

2006-12-27 Thread Bulat Ziganshin
Hello S.,

Wednesday, December 27, 2006, 2:24:00 AM, you wrote:

 Having just done a major refactor of the HAppS HTTP API to make it 
 much much easier to use, I am now thinking about simplifying the 
 current boilerplate associated with XML serialization and state 
 deserialization.

are you considered using Template Haskell to do it? at least it is used for
automatic generation of class instances for binary serialization


-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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


[Haskell-cafe] Dealing with incoherent instances

2006-12-27 Thread Vyacheslav Akhmechet

I'm looking at GHC's overlapping instances docs here:
http://web.mit.edu/ghc/www/users_guide/type-extensions.html#instance-decls
and I've ran into the incoherent instances problem.

Basically, I have a catch all instance that handles all types in a
generic manner using SYB introspection, and then I have type specific
instances that specialize behavior for certain types. This works with
overlapping instances extension but whenever I take advantage of this
functionality from polymorphic functions I run into the incoherent
instances.

If I enable incoherent instances GHC always picks the general case
which seems like the wrong thing to do. What I want it to do is delay
comitting to an instance until it's processing a specific invocation
of a polymorphic function. All the information is available at compile
time but I found no way to do this.

Is there a way to get around this problem?

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


[Haskell-cafe] Re: Seeking advice on a style question

2006-12-27 Thread apfelmus
Steve Schafer wrote:
 In my text/graphics formatting work, I find myself doing a lot of
 pipeline processing, where a data structure will undergo a number of
 step-by-step transformations from input to output. For example, I have a
 function that looks like this (the names have been changed to protect
 the innocent--and to focus on the structure):
 
  process :: a - b - c - d - e
  process x1 x2 x3 x4 = 
let y01   = f01 x1 x2 x3;
y02   = f02 x1;
y03   = f03 y02;
y04   = f04 y03;
y05   = f05 x1 y01 y04;
y06   = f06 x2 y05;
(y07,y08) = f07 y01 y06;
y09   = f08 y07;
(y10,y11) = f09 x2 x4 y09 y08;
y12   = f10 y10;
y13   = f11 y12;
y14   = f12 x1 x2 x3 y01 y13;
y15   = f13 y14;
y16   = f14 y15 y11
in y16
 [...]
 In principle, it could be
 managed with a bunch of nested StateT monads, but my attempts to do so
 seem to get so caught up in the bookkeeping that I lose the advantages
 mentioned above.
 [...]
 So here's the question: Is there a reasonable way to express this kind
 of process (where I suppose that reasonable means in keeping with
 Haskell-nature) that preserves the advantages mentioned above, but
 avoids having to explicitly pass all of the various bits of state
 around?

To me, it looks more like MonadReader than MonadState because I have the
impression that x1 and x2 are enivronments to fetch something from.
(Btw, MonadReader is best used as an Applicative Functor, but that's a
different story).

But in general, it's futile trying to simplify things without knowing
their meaning: names are *important*. I assume that your proper goal is
not to structure pipeline processes in full generality, but to simplify
the current one at hand.

Even if you wanted to simplify the general structure, I think you'd have
to make the types of the different yk explicit. Otherwise, the problem
is underspecified and/or one has to assume that they're all different
(modulo some equalities implied by type correctness).


Regards,
apfelmus

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


Re: [Haskell-cafe] Is there a printable copy of the (GHC) library references anywhere?

2006-12-27 Thread Kirsten Chevalier

On 12/27/06, Paul Moore [EMAIL PROTECTED] wrote:

I'd like to print out a copy of the GHC manuals, for reference. I've
got the Haskell 98 report, and the GHC user guide, but the only
documentation I've found for the hierarchical libraries is in HTML
format (generated from Haddock).

Is there a printable (preferably PDF) form of the library
documentation? Either all of it, or alternatively reasonably large
subsets?



There may be an easier way, but if nothing else, you could download
the HTML.tar.gz file for the library docs and then use latex2html to
generate TeX to generate a PDF. (Personally I wouldn't find it at all
useful to have a printed copy of the library docs, even though I do
like printed manuals, because I only ever consult them to look up a
specific function or type, which is a lot easier to do in the
hypertext version -- but YMMV.)

Cheers,
Kirsten

--
Kirsten Chevalier* [EMAIL PROTECTED] *Often in error, never in doubt
All we can ever do is lay a word in the hands of those who have put one in
ours. -- Richard Powers
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re[2]: [Haskell-cafe] Dealing with incoherent instances

2006-12-27 Thread Bulat Ziganshin
Hello Vyacheslav,

(returning to cafe)

Wednesday, December 27, 2006, 6:10:30 PM, you wrote:

 Ah, so the moment something is passed through a polymorphic function
 its type information is lost... This seems like a bug in the
 specification/implementation, no? This is most certainly not the
 desired behavior. It seems like the compiler has all the information
 it needs but still can't select the right instance.

sorry, but i think that it is how type class system should work in this
case. look at the page for details

 Are there ways to get around this problem?

existential types, for example. we need exact specification of your
problem. show me the code

 are you seen http://haskell.org/haskellwiki/OOP_vs_type_classes ?


-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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


Re: [Haskell-cafe] Is there a printable copy of the (GHC) library references anywhere?

2006-12-27 Thread Paul Moore

On 12/27/06, Kirsten Chevalier [EMAIL PROTECTED] wrote:

(Personally I wouldn't find it at all
useful to have a printed copy of the library docs, even though I do
like printed manuals, because I only ever consult them to look up a
specific function or type, which is a lot easier to do in the
hypertext version -- but YMMV.)


You're right - if I think about it, I'm not really looking for the
documentation, but more a paper or article which is a tour of the
GHC standard library. That's something that would be really useful
from a beginner's POV - and would be more useful than the reference
documentation in printed form. There seems to be a lot in the standard
library, but very little in the way of pointers on how much there is
(if that makes sense...)

Anyway, thanks for getting me to clarify my thoughts - I'll see what I
can find, and maybe write up anything I discover.

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


Re: [Haskell-cafe] Is there a printable copy of the (GHC) library references anywhere?

2006-12-27 Thread Neil Mitchell

Hi Paul,


You're right - if I think about it, I'm not really looking for the
documentation, but more a paper or article which is a tour of the
GHC standard library.


A tour of the Prelude:

http://undergraduate.csse.uwa.edu.au/units/230.301/lectureNotes/tourofprelude.html

Only a few of the standard libraries are useful unless you are doing
something specific. i.e. Data.Maybe is generally useful, but
Control.Monad.State is only useful if you are using a state monad.

If someone wrote a tour of Data.List/Data.Maybe as well as a few
common functions out of Control.Monad that would probably make a nice
companion to a tour of the prelude.

Thanks

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


Re[2]: [Haskell-cafe] Is there a printable copy of the (GHC) library references anywhere?

2006-12-27 Thread Bulat Ziganshin
Hello Paul,

Wednesday, December 27, 2006, 11:53:33 PM, you wrote:

 You're right - if I think about it, I'm not really looking for the
 documentation, but more a paper or article which is a tour of the
 GHC standard library. That's something that would be really useful

i just read library sources :)  in addition to information about features
implemented, it allows to learn good programming style used here


-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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


Re: [Haskell-cafe] Is there a printable copy of the (GHC) library references anywhere?

2006-12-27 Thread David House

On 27/12/06, Neil Mitchell [EMAIL PROTECTED] wrote:

If someone wrote a tour of Data.List/Data.Maybe as well as a few
common functions out of Control.Monad that would probably make a nice
companion to a tour of the prelude.


Maybe: http://en.wikibooks.org/wiki/Haskell/Hierarchical_libraries/Maybe
Lists: http://en.wikibooks.org/wiki/Haskell/List_processing (written
from a complete beginners POV, perhaps we need a more summary-like
article that involves Cale's fold diagrams).

For anything more complex (Maps, Arrays), it becomes impractical to
write a 'tour of the library' without duplicating the Haddock docs.
However, an introduction to Control.Monad à la the 'Monad
implementation' section in All About Monads would make a nice chapter
in the wikibook.

--
-David House, [EMAIL PROTECTED]
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: Re[2]: [Haskell-cafe] Dealing with incoherent instances

2006-12-27 Thread Vyacheslav Akhmechet

Ok, I think I solved the problem. It actually simplified my design and
made it significantly cleaner and nicer :) I won't bore people with
the code/explanation here but I'll publish an article about it on
defmacro.

Actually what I was trying to do is described in the SYB 3 paper.

Thanks,
- Slava.

On 12/27/06, Bulat Ziganshin [EMAIL PROTECTED] wrote:

Hello Vyacheslav,

(returning to cafe)

Wednesday, December 27, 2006, 6:10:30 PM, you wrote:

 Ah, so the moment something is passed through a polymorphic function
 its type information is lost... This seems like a bug in the
 specification/implementation, no? This is most certainly not the
 desired behavior. It seems like the compiler has all the information
 it needs but still can't select the right instance.

sorry, but i think that it is how type class system should work in this
case. look at the page for details

 Are there ways to get around this problem?

existential types, for example. we need exact specification of your
problem. show me the code

 are you seen http://haskell.org/haskellwiki/OOP_vs_type_classes ?


--
Best regards,
 Bulatmailto:[EMAIL PROTECTED]



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


[Haskell-cafe] constant functions

2006-12-27 Thread michael rice
I'm trying to learn Haskell and translating some Lisp
functions as exercises.

How would I write a Haskell function named ALWAYS that
behaves like this:

one = always 1
bozo = always clown

 map one [2,3,4,5,6]
[1,1,1,1,1]

 one 62
1

 map bozo [2,3,4,5,6]
[clown,clown ,clown, clown, clown]

 bozo 62
clown

i.e. ALWAYS returns a function with a single parameter
that is ignored, returning instead the value given to
ALWAYS when the function was created.

This is what I've been trying:

always :: (a - a) - a - a
always x = (\y - x)

one = always 1

Michael

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] constant functions

2006-12-27 Thread Bryan Burgers

I'm trying to learn Haskell and translating some Lisp
functions as exercises.

How would I write a Haskell function named ALWAYS that
behaves like this:

one = always 1
bozo = always clown

 map one [2,3,4,5,6]
[1,1,1,1,1]

 one 62
1

 map bozo [2,3,4,5,6]
[clown,clown ,clown, clown, clown]

 bozo 62
clown

i.e. ALWAYS returns a function with a single parameter
that is ignored, returning instead the value given to
ALWAYS when the function was created.

This is what I've been trying:

always :: (a - a) - a - a
always x = (\y - x)

one = always 1

Michael


First, you want 'one' to take an integer and return 1. So,


one :: Integer - Integer


since one = always 1, then


always 1 :: Integer - Integer


So, 'always' takes an Integer and returns an Integer - Integer


always :: Integer - (Integer - Integer)


But that's the same as


always :: Integer - Integer - Integer


You actually have the implementation correct, you just didn't have the
right type signature.


always first = (\second - first)


Of course, neither of these implementations need to be tied to
Integers; they can be polymorphic. So, we end up with:

always :: a - b - a  -- no reason the second parameter has to be the
same type as the first, so use 'b' instead of 'a'.
always first = (\_ - first)   -- replace 'second' with '_', because
we don't need to bind anything to the second parameter.

Does that makes sense?

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


Re: [Haskell-cafe] constant functions

2006-12-27 Thread Donald Bruce Stewart
nowgate:
 I'm trying to learn Haskell and translating some Lisp
 functions as exercises.
 
 How would I write a Haskell function named ALWAYS that
 behaves like this:
 
 one = always 1
 bozo = always clown
 
  map one [2,3,4,5,6]
 [1,1,1,1,1]
 
  one 62
 1
 
  map bozo [2,3,4,5,6]
 [clown,clown ,clown, clown, clown]
 
  bozo 62
 clown
 
 i.e. ALWAYS returns a function with a single parameter
 that is ignored, returning instead the value given to
 ALWAYS when the function was created.
 
 This is what I've been trying:
 
 always :: (a - a) - a - a
 always x = (\y - x)
 
 one = always 1


So there are two cases you want to handle: 
* return a list, if the argument is a list
* return a single value, if the argument is a single value.
We can write thes functions separately:

alwayList :: a - [b] - [a]
alwayList n xs = map (const n) xs


*Main let one = always 1
*Main one foo
[1,1,1]


*Main let bozo = always clown
*Main bozo haskell
[clown,clown,clown,clown,clown,clown,clown]

Now handle the non-list case:


alwaysAtom :: a - b - a
alwaysAtom a b = a

*Main let one = alwaysAtom 1
*Main one 'x'
1

Unifying these two under a common type class is left as an exercise ;)

I guess the type signature for such a class would be something like:

class Const a b a' | b - a', a' - a where

Something like that.

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


Re: [Haskell-cafe] constant functions

2006-12-27 Thread Matthew Brecknell
 This is what I've been trying:
 
 always :: (a - a) - a - a
 always x = (\y - x)

Your function implementation is correct, but the type is wrong. Try
this:

always :: a - b - a

Or, just use the function const, from the Prelude. :-)

The type system can be very handy when learning Haskell. If you think
you have the correct implementation but can't work out the type, just
start up an interpreter and ask it for the inferred type. For example:

Prelude let always x _ = x
Prelude :t always
always :: t - t1 - t

Once you have the type, ask Hoogle if the function already exists:

http://haskell.org/hoogle/?q=t+-%3E+t1+-%3E+t

And there is const at the top of the results. :-)


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


Re: [Haskell-cafe] constant functions

2006-12-27 Thread michael rice
Thanks! I figured I was close.

Didn't even know const was available.

I put together a compliment functions earlier

complement :: (a - Bool) - a - Bool
complement p x =  not (p x)

By the signature, the first argument is a function
(predicate) which when given a value returns a Bool?
And the second argument is just a value? And the
function returns a Bool?

 map (complement odd) [1,2,3,4,5,6]
[False,True,False,True,False,True]
 

By similar reasoning the always function would seem to
have a signature

a - (b - a)

where the first argument is just a value and the
return value is a function that when given a possibly
different value just returns the value originally
given to always?

Is that reasoning OK? Are

a - (b - a) and a - b - a the same signature?

So the inferred type is usually pretty accurate? These
signatures are a bit confusing. Is there a good
tutorial?

I'm using Hugs/Win XP just to scope out the language
right now. I tried what you suggested and got

Hugs let always x _ = x
ERROR - Syntax error in expression (unexpected end of
input)
Hugs

Isn't Hugs an interpreter?

Thanks again. Really interesting language Haskell.

Michael

--- Matthew Brecknell [EMAIL PROTECTED] wrote:

  This is what I've been trying:
  
  always :: (a - a) - a - a
  always x = (\y - x)
 
 Your function implementation is correct, but the
 type is wrong. Try
 this:
 
 always :: a - b - a
 
 Or, just use the function const, from the Prelude.
 :-)
 
 The type system can be very handy when learning
 Haskell. If you think
 you have the correct implementation but can't work
 out the type, just
 start up an interpreter and ask it for the inferred
 type. For example:
 
 Prelude let always x _ = x
 Prelude :t always
 always :: t - t1 - t
 
 Once you have the type, ask Hoogle if the function
 already exists:
 
 http://haskell.org/hoogle/?q=t+-%3E+t1+-%3E+t
 
 And there is const at the top of the results. :-)
 
 
 


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] constant functions

2006-12-27 Thread michael rice
Thanks Brian. I think these signatures are starting to
make sense. And I didn't know _ (don't care) could
be used like that. I'm liking Haskell more and more.

Michael

--- Bryan Burgers [EMAIL PROTECTED] wrote:

  I'm trying to learn Haskell and translating some
 Lisp
  functions as exercises.
 
  How would I write a Haskell function named ALWAYS
 that
  behaves like this:
 
  one = always 1
  bozo = always clown
 
   map one [2,3,4,5,6]
  [1,1,1,1,1]
 
   one 62
  1
 
   map bozo [2,3,4,5,6]
  [clown,clown ,clown, clown, clown]
 
   bozo 62
  clown
 
  i.e. ALWAYS returns a function with a single
 parameter
  that is ignored, returning instead the value given
 to
  ALWAYS when the function was created.
 
  This is what I've been trying:
 
  always :: (a - a) - a - a
  always x = (\y - x)
 
  one = always 1
 
  Michael
 
 First, you want 'one' to take an integer and return
 1. So,
 
  one :: Integer - Integer
 
 since one = always 1, then
 
  always 1 :: Integer - Integer
 
 So, 'always' takes an Integer and returns an Integer
 - Integer
 
  always :: Integer - (Integer - Integer)
 
 But that's the same as
 
  always :: Integer - Integer - Integer
 
 You actually have the implementation correct, you
 just didn't have the
 right type signature.
 
  always first = (\second - first)
 
 Of course, neither of these implementations need to
 be tied to
 Integers; they can be polymorphic. So, we end up
 with:
 
 always :: a - b - a  -- no reason the second
 parameter has to be the
 same type as the first, so use 'b' instead of 'a'.
 always first = (\_ - first)   -- replace 'second'
 with '_', because
 we don't need to bind anything to the second
 parameter.
 
 Does that makes sense?
 
 Bryan Burgers
 


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] constant functions

2006-12-27 Thread Donald Bruce Stewart
nowgate:
 Thanks! I figured I was close.
 
 Didn't even know const was available.
 
 I put together a compliment functions earlier
 
 complement :: (a - Bool) - a - Bool
 complement p x =  not (p x)
 
 By the signature, the first argument is a function
 (predicate) which when given a value returns a Bool?
 And the second argument is just a value? And the
 function returns a Bool?
 
  map (complement odd) [1,2,3,4,5,6]
 [False,True,False,True,False,True]
  
 
 By similar reasoning the always function would seem to
 have a signature
 
 a - (b - a)
 
 where the first argument is just a value and the
 return value is a function that when given a possibly
 different value just returns the value originally
 given to always?

Yep. Which may be written as:

const :: a - b - a

 Is that reasoning OK? Are
 
 a - (b - a) and a - b - a the same signature?

Yep.

 
 So the inferred type is usually pretty accurate? These

Yes :-)

 I'm using Hugs/Win XP just to scope out the language
 right now. I tried what you suggested and got
 
 Hugs let always x _ = x
 ERROR - Syntax error in expression (unexpected end of
 input)
 Hugs

let-bindings aren't supported in Hugs at the prompt, the solution is to
load the source from a file, with :reload, as you change it. You can
define them in GHC/GHCi however.

Also, you can use them locally as:

let always x _ = x in always 1 foo

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


Re: [Haskell-cafe] constant functions

2006-12-27 Thread michael rice
Hi Donald,

I think you misunderstood what I was asking. There's
not two cases. Maybe I'm not saying it sufficiently
well but the function ALWAYS just returns a function
that always returns the original argument to ALWAYS no
matter what else you give the resulting function.

when one is define as follows

 one = always 1

then

 one 4
1
 one abc
1
 one (2,3)
1
 one [0,4,8,2]
1
 map one [one,two,three]
[1,1,1]

The mapping example is just an alternative way of
illustrating the functionality. No matter what the
defined function is given it always gives back the
original value give to ALWAYS.

Michael



--- Donald Bruce Stewart [EMAIL PROTECTED] wrote:

 nowgate:
  I'm trying to learn Haskell and translating some
 Lisp
  functions as exercises.
  
  How would I write a Haskell function named ALWAYS
 that
  behaves like this:
  
  one = always 1
  bozo = always clown
  
   map one [2,3,4,5,6]
  [1,1,1,1,1]
  
   one 62
  1
  
   map bozo [2,3,4,5,6]
  [clown,clown ,clown, clown, clown]
  
   bozo 62
  clown
  
  i.e. ALWAYS returns a function with a single
 parameter
  that is ignored, returning instead the value given
 to
  ALWAYS when the function was created.
  
  This is what I've been trying:
  
  always :: (a - a) - a - a
  always x = (\y - x)
  
  one = always 1
 
 
 So there are two cases you want to handle: 
 * return a list, if the argument is a list
 * return a single value, if the argument is a
 single value.
 We can write thes functions separately:
 
 alwayList :: a - [b] - [a]
 alwayList n xs = map (const n) xs
 
 
 *Main let one = always 1
 *Main one foo
 [1,1,1]
 
 
 *Main let bozo = always clown
 *Main bozo haskell


[clown,clown,clown,clown,clown,clown,clown]
 
 Now handle the non-list case:
 
 
 alwaysAtom :: a - b - a
 alwaysAtom a b = a
 
 *Main let one = alwaysAtom 1
 *Main one 'x'
 1
 
 Unifying these two under a common type class is left
 as an exercise ;)
 
 I guess the type signature for such a class would be
 something like:
 
 class Const a b a' | b - a', a' - a where
 
 Something like that.
 
 -- Don
 


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] constant functions

2006-12-27 Thread Donald Bruce Stewart
nowgate:
 Hi Donald,
 
 I think you misunderstood what I was asking. There's
 not two cases. Maybe I'm not saying it sufficiently
 well but the function ALWAYS just returns a function
 that always returns the original argument to ALWAYS no
 matter what else you give the resulting function.
 
 when one is define as follows
 
  one = always 1
 
 then
 
  one 4
 1
  one abc
 1
  one (2,3)
 1
  one [0,4,8,2]
 1
  map one [one,two,three]
 [1,1,1]
 
 The mapping example is just an alternative way of
 illustrating the functionality. No matter what the
 defined function is given it always gives back the
 original value give to ALWAYS.

Ah yes, I must have missed the 'map one' in the original post.
Hence I thought you were looking for different behaviour for lists.

My mistake. Prelude.const is your friend :-)

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


Re: [Haskell-cafe] Seeking advice on a style question

2006-12-27 Thread Brian Hulley

Steve Schafer wrote:

In my text/graphics formatting work, I find myself doing a lot of
pipeline processing, where a data structure will undergo a number of
step-by-step transformations from input to output. For example, I
have a function that looks like this (the names have been changed to
protect the innocent--and to focus on the structure):

 process :: a - b - c - d - e
 process x1 x2 x3 x4 =
   let y01   = f01 x1 x2 x3;
   y02   = f02 x1;
   y03   = f03 y02;
   y04   = f04 y03;
   y05   = f05 x1 y01 y04;
   y06   = f06 x2 y05;
   (y07,y08) = f07 y01 y06;
   y09   = f08 y07;
   (y10,y11) = f09 x2 x4 y09 y08;
   y12   = f10 y10;
   y13   = f11 y12;
   y14   = f12 x1 x2 x3 y01 y13;
   y15   = f13 y14;
   y16   = f14 y15 y11
   in y16


Disclaimer: just re-written by hand so needs double-checking before use:

   process x1 x2 x3 x4 =
   let
   y01 = f01 x1 x2 x3
   (y07, y08) = f07 y01 (f06 x2 (f05 x1 y01 (f04 (f03 y02
   (y10, y11) = f09 x2 x4 (f08 y07) y08
   in
   f14 (f13 (f12 x1 x2 x3 y01 (f11 (f10 y10 y11

You can also make it look more like the diagram by using more indentation 
eg:


   process x1 x2 x3 x4 =
   let
   y01 =
   f01
   x1
   x2
   x3
   (y07, y08) =
   f07
   y01
   (f06
   x2
   (f05
   x1
   y01
   (f04
   (f03
   y02
   ...

Best regards, Brian.
--
http://www.metamilk.com 


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


Re: [Haskell-cafe] constant functions

2006-12-27 Thread Brandon S. Allbery KF8NH


On Dec 27, 2006, at 22:55 , michael rice wrote:


By similar reasoning the always function would seem to
have a signature

a - (b - a)

where the first argument is just a value and the
return value is a function that when given a possibly
different value just returns the value originally
given to always?

Is that reasoning OK? Are

a - (b - a) and a - b - a the same signature?


This is a point that has been glossed over a bit:  Haskell has the  
notion of partial application.  If you want to start with a function  
that takes two values, and return a function that takes one value and  
uses the one previously passed in, you just invoke the function with  
one parameter; Haskell will produce a function which takes a single  
argument to complete the expression.  Using (*) (prefix version of  
multiplication) as an example:


Prelude :t ((*) 2)
((*) 2) :: (Num t) = t - t
Prelude let x2 = ((*) 2) in x2 5
10

This shows the equivalence of the type signatures (a - a - a) and  
(a - (a - a)), and is one of the strengths of Haskell:  you can  
pass a section (a partially expanded function) wherever a function  
is expected.


Prelude map ((*) 2) [1..5]
[2,4,6,8,10]

This doesn't only work for prefix functions, by the way; the above  
example is more naturally written as (2*):


Prelude :t (2*)
(2*) :: (Num t) = t - t
Prelude map (2*) [1..5]
[2,4,6,8,10]

You can also say (*2), which provides the right-hand argument; this  
is useful for non-commutative functions like (/).  But don't try it  
with (-), because you'll trip over an unfortunate parsing hack for  
negative numbers:


Prelude :t (-2) -- whoops, it's a number, not a function!
(-2) :: (Num a) = a

The Prelude provides a workaround for this, though:

Prelude :t (subtract 2)
(subtract 2) :: (Num t) = t - t

--
brandon s. allbery[linux,solaris,freebsd,perl] [EMAIL PROTECTED]
system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED]
electrical and computer engineering, carnegie mellon universityKF8NH



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


Re: [Haskell-cafe] constant functions

2006-12-27 Thread Matthew Brecknell
 complement :: (a - Bool) - a - Bool
 complement p x =  not (p x)

 By the signature, the first argument is a function
 (predicate) which when given a value returns a Bool?
 And the second argument is just a value? And the
 function returns a Bool?

Indeed. In the type expression, the lower-case identifiers are type
variables, while the upper-case identifiers are types. Thus, a could
be instantiated to any type, with the constraint that both appearances
of a are the same type.

 map (complement odd) [1,2,3,4,5,6]

Typically, you would use function composition here:

map (not.odd) [1..6]

If you really want a seperate complement function, you could define it
using a section:

complement = (not.)

 By similar reasoning the always function would seem to
 have a signature
 
 a - (b - a)
 
 where the first argument is just a value and the
 return value is a function that when given a possibly
 different value just returns the value originally
 given to always?
 
 Is that reasoning OK? Are
 
 a - (b - a) and a - b - a the same signature?

Yes. Function application (-) is right-associative in a type
expression. What about a value expression?

f a b === (f a) b

Looks like an inconsistency? Not if you think about it. :-)

Of course, this is what curried functions and partial application are
all about.

 So the inferred type is usually pretty accurate? These
 signatures are a bit confusing. Is there a good
 tutorial?

http://haskell.org/tutorial, particularly chapter 2.

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