Jens Petersen | 2 Jun 2002 08:57
X-Face
Picon
Favicon

Re: HTTP Implementation

Hi Warrick,

"Warrick Gray" <oinutter <at> hotmail.com> writes:

> I've been tinkering with a client-side HTTP/1.1
> implementation for Haskell.  [..] In the interests of
> finding all bugs and giving something for nothing I've
> made the code available:
> 
> http://homepages.paradise.net.nz/warrickg/haskell/http

Thanks I think it is a nice library.

> Significantly missing is any hint of SSL and request
> pipelining.  Suggestions on improvements are welcome.

I tried HTTP.hs and Base64.hs a little and they seem to work
well so far.

I think your http library would make a useful addition to
the Haskell libraries, at least as a starting point for a
standard HTTP library.

Jens
xoo | 5 Jun 2002 13:59
Picon
Favicon

(no subject)

hi.. i was just wondering if some body could give a simple equation for the following situation.other than recursion plz..
 
occurrences :: Eq a => a -> [a] -> [a]
--occurrences xs ys returns the number of times that xs  occurs in ys
 
 
thanks
Cagdas Ozgenc | 5 Jun 2002 14:33
Picon
Favicon

type equivalency

Greetings.
 
I know 2 special type constructors(there might be other that I do not know yet) -> and ( , )  where structural type equivalency is enforced and we can also create new types with an algebric type constructor notation where name equivalency is enforced.
 
What is the rationale? I mean why 2 special type constructors, but not 5, or 10 or N?
 
Thanks for taking time.
Andy Fugard | 5 Jun 2002 20:04

RE: Counting occurrences question

>===== Original Message From "xoo" <ixoo21 <at> hotmail.com> =====
>hi.. i was just wondering if some body could give a simple equation for the 
following situation.other than recursion plz..
>
>occurrences :: Eq a => a -> [a] -> [a]
>--occurrences xs ys returns the number of times that xs  occurs in ys

You may find it easier if you make

  occurrences :: Eq a => a -> [a] -> Integer

since it would seem it is to return a number, and not another list!

Also I would guess the function will have a form something like

  occurrences x xs = foldr (countOp x) 0 xs
      where countOp :: Eq a => a -> a -> Integer -> Integer
            ...

I'm not sure if I should go any further, in case this is a homework 
question...

Andy

--
[ Andy Fugard ]
[ +44 (0)7901 603075 ]
Hal Daume III | 5 Jun 2002 20:08
Picon
Favicon

RE: Counting occurrences question

Probably is a homework question, so HINT:

you can do it using 2 and only 2 prelude functions and no additional
function definitions of your own.

--
Hal Daume III

 "Computer science is no more about computers    | hdaume <at> isi.edu
  than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume

On Wed, 5 Jun 2002, Andy Fugard wrote:

> >===== Original Message From "xoo" <ixoo21 <at> hotmail.com> =====
> >hi.. i was just wondering if some body could give a simple equation for the 
> following situation.other than recursion plz..
> >
> >occurrences :: Eq a => a -> [a] -> [a]
> >--occurrences xs ys returns the number of times that xs  occurs in ys
> 
> 
> You may find it easier if you make
> 
>   occurrences :: Eq a => a -> [a] -> Integer
> 
> since it would seem it is to return a number, and not another list!
> 
> Also I would guess the function will have a form something like
> 
>   occurrences x xs = foldr (countOp x) 0 xs
>       where countOp :: Eq a => a -> a -> Integer -> Integer
>             ...
> 
> I'm not sure if I should go any further, in case this is a homework 
> question...
> 
> Andy
> 
> --
> [ Andy Fugard ]
> [ +44 (0)7901 603075 ]
> 
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe <at> haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 
Hannah Schroeter | 5 Jun 2002 20:11
Picon
Picon
Favicon

Re: Counting occurrences question

Hello!

On Wed, Jun 05, 2002 at 07:04:28PM +0100, Andy Fugard wrote:
> >===== Original Message From "xoo" <ixoo21 <at> hotmail.com> =====
> >hi.. i was just wondering if some body could give a simple equation for the 
> following situation.other than recursion plz..

> >occurrences :: Eq a => a -> [a] -> [a]
> >--occurrences xs ys returns the number of times that xs  occurs in ys

> You may find it easier if you make

>   occurrences :: Eq a => a -> [a] -> Integer

> since it would seem it is to return a number, and not another list!

Yep. And not call the parameter for the single 'a' "xs". That's
misleading.

> Also I would guess the function will have a form something like

>   occurrences x xs = foldr (countOp x) 0 xs
>       where countOp :: Eq a => a -> a -> Integer -> Integer
>             ...

> [...]

Why not combine filter and length appropriately?

Kind regards,

Hannah.
Andy Fugard | 5 Jun 2002 20:20

Re: Counting occurrences question

At 20:11 05/06/2002 +0200, Hannah Schroeter wrote:
>Why not combine filter and length appropriately?

Pass -- I'm also a newbie, and haven't got as far as filter.

*Looks up filter*

Well, there's his homework done :-)
Tom Pledger | 5 Jun 2002 22:22

type equivalency

Cagdas Ozgenc writes:
 | Greetings.
 | 
 | I know 2 special type constructors(there might be other that I do
 | not know yet) -> and ( , ) where structural type equivalency is
 | enforced and we can also create new types with an algebric type
 | constructor notation where name equivalency is enforced.
 | 
 | What is the rationale? I mean why 2 special type constructors, but
 | not 5, or 10 or N?
 | 
 | Thanks for taking time.

-> and (,) are names of type contructors, each with kind *->*->*.

Offhand, I don't see any difference in the way we'd test equivalency
involving -> or (,) or D, where:

    data D a b = MkD a b

If that doesn't help, will you please give a more concrete example of
what you mean?

Regards,
Tom
Cagdas Ozgenc | 5 Jun 2002 23:33
Picon
Favicon

Re: type equivalency

For example all functions with Int -> Int are type equivalent, because
structural equivalency is used. Most of the time the functions are not
compatible because they have different pre/post conditions, even though they
seem to have the same input output types. I rather make my functions an
instance of a type-class to tell the compiler that they can be used
interchangably. For example

sqrt :: Float -> Float
sqrt a =  /* pre : a >= 0 */

negate :: Float -> Float
/* no precondition */

are different functions. You cannot just plug one in place of another (you
can in Haskell because of structural type equivalency).

Also a function working over (Int,Int) will do so even if the numbers are
totally irrelevant to that function. They maybe the number of
(apples,oranges) or number of (books,authors).

However,

data D a b = MkD a b

data E a b = MkE a b

(D Int Int) and (E Int Int) are trated as different because of name
equivalency testing.

Basically there are 2 type constructors -> ( , ) with structural
equivalency, which is odd. Someone just dumped some idiosyncracies of lamda
calculus into the language.

Thanks again.

> Cagdas Ozgenc writes:
>  | Greetings.
>  |
>  | I know 2 special type constructors(there might be other that I do
>  | not know yet) -> and ( , ) where structural type equivalency is
>  | enforced and we can also create new types with an algebric type
>  | constructor notation where name equivalency is enforced.
>  |
>  | What is the rationale? I mean why 2 special type constructors, but
>  | not 5, or 10 or N?
>  |
>  | Thanks for taking time.
>
> -> and (,) are names of type contructors, each with kind *->*->*.
>
> Offhand, I don't see any difference in the way we'd test equivalency
> involving -> or (,) or D, where:
>
>     data D a b = MkD a b
>
> If that doesn't help, will you please give a more concrete example of
> what you mean?
>
> Regards,
> Tom
Jon Fairbairn | 5 Jun 2002 23:39
X-Face
Picon
Picon
Favicon

Re: type equivalency

> For example all functions with Int -> Int are type equivalent
> However,
> 
> data D a b = MkD a b

All objects D Int Int are type equivalent.  I'm not sure what
your question means, otherwise.

If you define 

data Function a b = F (a -> b)

apply:: Function a b -> a -> b
apply (F f) a = f a

you add an extra level of constructor, but you can still use
anything of type Function Int Int where Function Int Int is
required:

square:: Function Int Int
square = F (\ a -> a*a)

sqare_root:: Function Int Int
square_root = F (\ a -> round (sqrt (fromIntegral a)))

E&OE -- it's about my bedtime.

--

-- 
Jón Fairbairn                                 Jon.Fairbairn <at> cl.cam.ac.uk
31 Chalmers Road                                         jf <at> cl.cam.ac.uk
Cambridge CB1 3SZ            +44 1223 570179 (after 14:00 only, please!)

Gmane