[Haskell-cafe] safe vs unsafe

2008-06-23 Thread Galchin, Vasili
Hello,

At runtime, I am getting 

aio: schedule: re-entered unsafely.
   Perhaps a 'foreign import unsafe' should be 'safe'?

I want to understand from an implementation viewpoint .. deeper. This is a
GC issue yes?

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


[Haskell-cafe] Re: number-parameterized types and heterogeneous lists

2008-06-23 Thread oleg

Luke Palmer wrote in response to Harald ROTTER
> > I also wonder if there is some kind of "generalized" foldr such that, e.g.
> >  D1 $ D0 $ D0 $ Sz = specialFoldr ($) Sz [D1,D0,D0]
> > I think that this foldr must be some "special" foldr that augments the data
> > type of the result in each foldr step.
> > Would this be possible or am I just chasing phantoms ?

> Mostly I believe you are.  What you are describing is firmly in the
> realm of dependent types, far beyond Haskell's type system. See
> Epigram or Agda for languages which have attempted to tackle this
> problem.

First of all, Haskell (as implemented by released versions of GHC for
at least two years) already permits dependent types, in the
strict sense of a type of an expression being determined by the value
of one argument of that expression:

http://okmij.org/ftp/Computation/tagless-typed.html#tc-GADT-tc

Second, (values of) types like D0 and D1 can be collected in a
heterogenous list (HList), which does have the corresponding fold
operator, called HFoldr in

http://darcs.haskell.org/HList/Data/HList/HListPrelude.hs

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


Re: [Haskell-cafe] Re: "C" buffer suggestions??

2008-06-23 Thread David Roundy
See the Data.ByteString.Internal docs:

http://www.haskell.org/ghc/docs/latest/html/libraries/bytestring/Data-ByteString-Internal.html#v%3AtoForeignPtr

Of course, you'd better not write to the contents of that pointer, or
bad things could happen...

David

On Mon, Jun 23, 2008 at 08:18:23PM -0500, Galchin, Vasili wrote:
> e.g. on Word8 .
> 
>  let aiocb = AIOCB{
>aioFd=fd,
>aioLioOpcode=0,
>aioReqPrio=0,
>aioOffset=0,
>aioBuf=??,<   Ptr Word8
>aioBytes=128,
>aioSigevent=event}
> 
> ???
> 
> Kind regards, Vasili
> 
> On Mon, Jun 23, 2008 at 8:13 PM, Galchin, Vasili <[EMAIL PROTECTED]>
> wrote:
> 
> > ok .
> >
> > 1) how do I marshall from ByteString to char * (poke)??
> >
> > 2) how do I write
> >
> >  let x =??? :: Word8
> >
> > 3) how do I write
> >
> >  let y = ??? ::ByteString
> >
> > Kind regards, Vasili
> >
> >
> >
> > On Mon, Jun 23, 2008 at 6:13 PM, Adam Langley <[EMAIL PROTECTED]>
> > wrote:
> >
> >> On Mon, Jun 23, 2008 at 2:27 PM, Don Stewart <[EMAIL PROTECTED]> wrote:
> >> > So heap allocated and collected, but not moved.
> >>
> >> My bad. In that case, you might want to work with ByteStrings all the
> >> way since it might make building the visible interface (which probably
> >> should use ByteStrings) easier.
> >>
> >>
> >> AGL
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: "C" buffer suggestions??

2008-06-23 Thread Galchin, Vasili
e.g. on Word8 .

 let aiocb = AIOCB{
   aioFd=fd,
   aioLioOpcode=0,
   aioReqPrio=0,
   aioOffset=0,
   aioBuf=??,<   Ptr Word8
   aioBytes=128,
   aioSigevent=event}

???

Kind regards, Vasili

On Mon, Jun 23, 2008 at 8:13 PM, Galchin, Vasili <[EMAIL PROTECTED]>
wrote:

> ok .
>
> 1) how do I marshall from ByteString to char * (poke)??
>
> 2) how do I write
>
>  let x =??? :: Word8
>
> 3) how do I write
>
>  let y = ??? ::ByteString
>
> Kind regards, Vasili
>
>
>
> On Mon, Jun 23, 2008 at 6:13 PM, Adam Langley <[EMAIL PROTECTED]>
> wrote:
>
>> On Mon, Jun 23, 2008 at 2:27 PM, Don Stewart <[EMAIL PROTECTED]> wrote:
>> > So heap allocated and collected, but not moved.
>>
>> My bad. In that case, you might want to work with ByteStrings all the
>> way since it might make building the visible interface (which probably
>> should use ByteStrings) easier.
>>
>>
>> AGL
>>
>> --
>> Adam Langley [EMAIL PROTECTED] http://www.imperialviolet.org
>>
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: "C" buffer suggestions??

2008-06-23 Thread Galchin, Vasili
ok .

1) how do I marshall from ByteString to char * (poke)??

2) how do I write

 let x =??? :: Word8

3) how do I write

 let y = ??? ::ByteString

Kind regards, Vasili


On Mon, Jun 23, 2008 at 6:13 PM, Adam Langley <[EMAIL PROTECTED]>
wrote:

> On Mon, Jun 23, 2008 at 2:27 PM, Don Stewart <[EMAIL PROTECTED]> wrote:
> > So heap allocated and collected, but not moved.
>
> My bad. In that case, you might want to work with ByteStrings all the
> way since it might make building the visible interface (which probably
> should use ByteStrings) easier.
>
>
> AGL
>
> --
> Adam Langley [EMAIL PROTECTED] http://www.imperialviolet.org
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Help with generalizing function

2008-06-23 Thread Richard A. O'Keefe


On 23 Jun 2008, at 6:30 pm, leledumbo wrote:
I've successfully create a function to return lists of N-ple that  
satisfy the

following function:
x1 + x2 + x3 + ... + xN = C
But unfortunately, it's not generic.


Why do you want it to be a tuple?  All the elements are the same type,  
so it

might as well be a list.

part 0 c | c == 0 = [[]]
part (n+1) c | c >= 0 = [(x:xs) | x <- [0..c],
  xs <- part n (c-x)]

(WARNING: UNTESTED CODE!)
Knuth TAOCP Volume 4 has some stuff on enumerating partitions.

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


Re: [Haskell-cafe] Re: "C" buffer suggestions??

2008-06-23 Thread Adam Langley
On Mon, Jun 23, 2008 at 2:27 PM, Don Stewart <[EMAIL PROTECTED]> wrote:
> So heap allocated and collected, but not moved.

My bad. In that case, you might want to work with ByteStrings all the
way since it might make building the visible interface (which probably
should use ByteStrings) easier.


AGL

-- 
Adam Langley [EMAIL PROTECTED] http://www.imperialviolet.org
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] number-parameterized types and heterogeneous lists

2008-06-23 Thread Ryan Ingram
Literate haskell response:
> {-# LANGUAGE GADTs, RankNTypes #-}
> module Digits where
> {-

On 6/23/08, Luke Palmer <[EMAIL PROTECTED]> wrote:

> > I also wonder if there is some kind of "generalized" foldr such that, e.g.
> >  D1 $ D0 $ D0 $ Sz = specialFoldr ($) Sz [D1,D0,D0]
> > I think that this foldr must be some "special" foldr that augments the data
> > type of the result in each foldr step.
> > Would this be possible or am I just chasing phantoms ?

> Mostly I believe you are.  What you are describing is firmly in the
> realm of dependent types, far beyond Haskell's type system. See
> Epigram or Agda for languages which have attempted to tackle this
> problem.

> -}

I'm not so sure, as long as you are willing to live with the result
being existentially quantified.  Here's an example:
ghci> mkNat [x1, x0, x3, x2]
(reifyInt 1032)
ghci> :t mkNat [x1, x0, x3, x2]
mkNat [x1, x0, x3, x2] :: AnyNat

I slightly specialize the constructors to wrap them in existential types:
d0 = AnyNat . D0  -- and so on for d1..d9
x0 = NatFn d0 -- and so on for x1..x9


Full code:

> data Sz = Sz
> data D0 a = D0 a
> data D1 a = D1 a
> data D2 a = D2 a
> data D3 a = D3 a
> data D4 a = D4 a
> data D5 a = D5 a
> data D6 a = D6 a
> data D7 a = D7 a
> data D8 a = D8 a
> data D9 a = D9 a

> class Nat n where
>toIntAccum :: n -> Integer -> Integer

> toInt :: Nat n => n -> Integer
> toInt n = toIntAccum n 0

> instance Nat Sz where toIntAccum _ acc = acc

> instance Nat a => Nat (D0 a) where
> toIntAccum (D0 n) acc = toIntAccum n (10 * acc + 0)
> instance Nat a => Nat (D1 a) where
> toIntAccum (D1 n) acc = toIntAccum n (10 * acc + 1)
> instance Nat a => Nat (D2 a) where
> toIntAccum (D2 n) acc = toIntAccum n (10 * acc + 2)
> instance Nat a => Nat (D3 a) where
> toIntAccum (D3 n) acc = toIntAccum n (10 * acc + 3)
> instance Nat a => Nat (D4 a) where
> toIntAccum (D4 n) acc = toIntAccum n (10 * acc + 4)
> instance Nat a => Nat (D5 a) where
> toIntAccum (D5 n) acc = toIntAccum n (10 * acc + 5)
> instance Nat a => Nat (D6 a) where
> toIntAccum (D6 n) acc = toIntAccum n (10 * acc + 6)
> instance Nat a => Nat (D7 a) where
> toIntAccum (D7 n) acc = toIntAccum n (10 * acc + 7)
> instance Nat a => Nat (D8 a) where
> toIntAccum (D8 n) acc = toIntAccum n (10 * acc + 8)
> instance Nat a => Nat (D9 a) where
> toIntAccum (D9 n) acc = toIntAccum n (10 * acc + 9)

> data AnyNat where AnyNat :: Nat n => n -> AnyNat

> d0, d1, d2, d3, d4, d5, d6, d7, d8, d9 :: Nat n => n -> AnyNat
> d0 = AnyNat . D0
> d1 = AnyNat . D1
> d2 = AnyNat . D2
> d3 = AnyNat . D3
> d4 = AnyNat . D4
> d5 = AnyNat . D5
> d6 = AnyNat . D6
> d7 = AnyNat . D7
> d8 = AnyNat . D8
> d9 = AnyNat . D9

> reifyDigit :: Integer -> (forall n. Nat n => n -> AnyNat)
> reifyDigit 0 = d0
> reifyDigit 1 = d1
> reifyDigit 2 = d2
> reifyDigit 3 = d3
> reifyDigit 4 = d4
> reifyDigit 5 = d5
> reifyDigit 6 = d6
> reifyDigit 7 = d7
> reifyDigit 8 = d8
> reifyDigit 9 = d9
> reifyDigit _ = error "not a digit"

> reifyIntAccum :: Integer -> AnyNat -> AnyNat
> reifyIntAccum 0 acc  = acc
> reifyIntAccum n (AnyNat rhs) = let (l, r) = divMod n 10 in
>reifyIntAccum l (reifyDigit r rhs)

> reifyInt :: Integer -> AnyNat
> reifyInt n | n < 0  = error "negative"
> reifyInt n  = reifyIntAccum n (AnyNat Sz)

> instance Show AnyNat where
> show (AnyNat n) = "(reifyInt " ++ show (toInt n) ++ ")"

> data NatFn where NatFn :: (forall n. Nat n => n -> AnyNat) -> NatFn

> x0, x1, x2, x3, x4, x5, x6, x7, x8, x9 :: NatFn
> x0 = NatFn d0
> x1 = NatFn d1
> x2 = NatFn d2
> x3 = NatFn d3
> x4 = NatFn d4
> x5 = NatFn d5
> x6 = NatFn d6
> x7 = NatFn d7
> x8 = NatFn d8
> x9 = NatFn d9

> foldNat :: [NatFn] -> AnyNat -> AnyNat
> foldNat []   z = z
> foldNat (NatFn f:xs) z = case foldNat xs z of AnyNat n -> f n

> mkNat :: [NatFn] -> AnyNat
> mkNat xs = foldNat xs (AnyNat Sz)

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


Re: [Haskell-cafe] IMAP and NNTP libraries

2008-06-23 Thread John Goerzen
Adam Langley wrote:
> On Sat, Jun 21, 2008 at 10:52 PM, Maurí­cio <[EMAIL PROTECTED]> wrote:
>> Are there mature libraries for IMAP and NNTP
>> available to Haskell?
> 
> Pretty much, if a Haskell library exist it will be listed at [1].
> Since I don't see anything for IMAP, nor NNTP I can be pretty sure
> that the answer is "no" I'm afraid. Perhaps you would care to write
> such libraries if you have a need?

I'm aware of neither.  NNTP is a pretty trivial protocol, and should be
trivial to implement.

IMAP is more complex.  I may write such a library someday, if I ever
port OfflineIMAP to Haskell, but it will not be real soon now by any means.

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


Re: [Haskell-cafe] IMAP and NNTP libraries

2008-06-23 Thread Don Stewart
agl:
> On Sat, Jun 21, 2008 at 10:52 PM, Maurí­cio <[EMAIL PROTECTED]> wrote:
> > Are there mature libraries for IMAP and NNTP
> > available to Haskell?
> 
> Pretty much, if a Haskell library exist it will be listed at [1].
> Since I don't see anything for IMAP, nor NNTP I can be pretty sure
> that the answer is "no" I'm afraid. Perhaps you would care to write
> such libraries if you have a need?
> 
> 
> [1] http://hackage.haskell.org/packages/archive/pkg-list.html

Or FFI bind to some existing library. cabal-install will take care of
the rest.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: "C" buffer suggestions??

2008-06-23 Thread Don Stewart
agl:
> 2008/6/23 Galchin, Vasili <[EMAIL PROTECTED]>:
> > Basically I want to model POSIX async io "aiocb"(
> > http://uw714doc.sco.com/en/man/html.5/aiocb.5.html) in Haskell .. in
> > particular the aiocb field "aio_buf"!
> 
> That's a mutable buffer, so this has to be pretty low level in your
> wrapping of the AIO interface. I would keep it as a Ptr Word8 at that
> point. ByteStrings are probably the correct type for the user visible
> interface, but I would guess not here.
> 
> Plus, ByteString data lives in the Haskell heap so could get moved
> about by the collector. Since an AIO interface is probably going to

ByteStrings are allocated into pinned memory, so they're easy to pass to
C and back. It uses the fast 'mallocPlainForeignPtr' api,

-- GHC notes: 'mallocPlainForeignPtr' has a heavily optimised
-- implementation in GHC.  It uses pinned memory in the garbage
-- collected heap, as for mallocForeignPtr. 

So heap allocated and collected, but not moved.

> return while the IO is still in progress, you don't want to stop the
> collector, but nor do you want the data moving because the kernel's
> pointer isn't going to move with it.

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


Re: [Haskell-cafe] IMAP and NNTP libraries

2008-06-23 Thread Chris Eidhof

On 23 jun 2008, at 22:26, Spencer Janssen wrote:


On Sun, Jun 22, 2008 at 02:52:33AM -0300, Maurí cio wrote:

Hi,

Are there mature libraries for IMAP and NNTP
available to Haskell?

Thanks,
Maurício


There is the haskellnet project:

   http://darcs.haskell.org/SoC/haskellnet/

I'm not sure whether it is mature or maintained.
I don't think it's maintained or mature: last time I checked, I  
couldn't get it to work (probably due to library changes), and there  
is not a lot of documentation nor comments.


I was actually thinking of writing a binding myself, to libEtPan!,  
which seems to have a well-documented and clean interface. I'm not  
sure how hard this is though. I've also looked a bit at the UW c- 
client, but I haven't seen any good examples of how to use it.


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


Re: [Haskell-cafe] Re: "C" buffer suggestions??

2008-06-23 Thread Adam Langley
On Mon, Jun 23, 2008 at 1:15 PM, Galchin, Vasili <[EMAIL PROTECTED]> wrote:
>  I tried to write a test value of Word8 without success. Can you give an 
> example?

I'm not quite sure what you would want in such an example. See [1] for
the malloc function. Then you take the result and wrap it with [2]:
 fp <- mallocBytes nbytes >>= newForeignPtr finalizerFree

When you want to use it, use [3] to unwrap fp and get a raw Ptr Word8.
You can pass these to foreign functions any place they expect a
uint8_t *, char * etc.


[1] 
http://www.haskell.org/hoogle/hoodoc.cgi?module=Foreign.Marshal.Alloc&name=mallocBytes&mode=func
[2] 
http://www.haskell.org/hoogle/hoodoc.cgi?module=Foreign.ForeignPtr&name=newForeignPtr&mode=func
[3] 
http://www.haskell.org/hoogle/hoodoc.cgi?module=Foreign.ForeignPtr&name=withForeignPtr&mode=func

-- 
Adam Langley [EMAIL PROTECTED] http://www.imperialviolet.org
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] IMAP and NNTP libraries

2008-06-23 Thread Spencer Janssen
On Sun, Jun 22, 2008 at 02:52:33AM -0300, Maurí­cio wrote:
> Hi,
>
> Are there mature libraries for IMAP and NNTP
> available to Haskell?
>
> Thanks,
> Maurício

There is the haskellnet project:

http://darcs.haskell.org/SoC/haskellnet/

I'm not sure whether it is mature or maintained.


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


Re: [Haskell-cafe] Re: "C" buffer suggestions??

2008-06-23 Thread Galchin, Vasili
On Mon, Jun 23, 2008 at 12:07 PM, Adam Langley <[EMAIL PROTECTED]>
wrote:

> 2008/6/23 Galchin, Vasili <[EMAIL PROTECTED]>:
> > Basically I want to model POSIX async io "aiocb"(
> > http://uw714doc.sco.com/en/man/html.5/aiocb.5.html) in Haskell .. in
> > particular the aiocb field "aio_buf"!
>
> That's a mutable buffer, so this has to be pretty low level in your
> wrapping of the AIO interface. I would keep it as a Ptr Word8 at that
> point. ByteStrings are probably the correct type for the user visible
> interface, but I would guess not here.

 I tried to write a test value of Word8 without success. Can you give an
example?

>
>
> Plus, ByteString data lives in the Haskell heap so could get moved
> about by the collector. Since an AIO interface is probably going to
> return while the IO is still in progress, you don't want to stop the
> collector, but nor do you want the data moving because the kernel's
> pointer isn't going to move with it.

   ^^ Interesting about moving around in the heap. I cannot use it for
AIO.

>
>
> AGL
>
> --
> Adam Langley [EMAIL PROTECTED] http://www.imperialviolet.org
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] IMAP and NNTP libraries

2008-06-23 Thread Adam Langley
On Sat, Jun 21, 2008 at 10:52 PM, Maurí­cio <[EMAIL PROTECTED]> wrote:
> Are there mature libraries for IMAP and NNTP
> available to Haskell?

Pretty much, if a Haskell library exist it will be listed at [1].
Since I don't see anything for IMAP, nor NNTP I can be pretty sure
that the answer is "no" I'm afraid. Perhaps you would care to write
such libraries if you have a need?


[1] http://hackage.haskell.org/packages/archive/pkg-list.html

-- 
Adam Langley [EMAIL PROTECTED] http://www.imperialviolet.org
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: "C" buffer suggestions??

2008-06-23 Thread Adam Langley
2008/6/23 Galchin, Vasili <[EMAIL PROTECTED]>:
> Basically I want to model POSIX async io "aiocb"(
> http://uw714doc.sco.com/en/man/html.5/aiocb.5.html) in Haskell .. in
> particular the aiocb field "aio_buf"!

That's a mutable buffer, so this has to be pretty low level in your
wrapping of the AIO interface. I would keep it as a Ptr Word8 at that
point. ByteStrings are probably the correct type for the user visible
interface, but I would guess not here.

Plus, ByteString data lives in the Haskell heap so could get moved
about by the collector. Since an AIO interface is probably going to
return while the IO is still in progress, you don't want to stop the
collector, but nor do you want the data moving because the kernel's
pointer isn't going to move with it.

AGL

-- 
Adam Langley [EMAIL PROTECTED] http://www.imperialviolet.org
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] number-parameterized types and heterogeneous lists

2008-06-23 Thread Anton Tayanovskyy
Alfonso,

Thanks! For didactic purposes I will defer looking into your code. It
does not always help to know the correct solution :)


Bests,

--A

On Mon, Jun 23, 2008 at 11:26 AM, Alfonso Acosta
<[EMAIL PROTECTED]> wrote:
> Inspired in Oleg's ideas, I implemented the packages type-level and
> parameterized-data (which includes number-parameterized vectors).
>
>
> To get an idea about how they work you might want to read their
> haddock documentation in hackage:
>
> http://hackage.haskell.org/cgi-bin/hackage-scripts/package/type-level
> http://hackage.haskell.org/cgi-bin/hackage-scripts/package/parameterized-data
>
> You can get their darcs repositories (including some minor updates) from:
>
> darcs get http://code.haskell.org/type-level
> darcs get http://code.haskell.org/parameterized-data
>
> On Fri, Jun 20, 2008 at 8:01 AM, Harald ROTTER <[EMAIL PROTECTED]> wrote:
>>
>> Dear Haskellers,
>>
>> after reading Oleg Kiselyov's paper on number-parameterized types I started
>> to play around with
>> the class Digits that encodes decimal numbers in types. The "typed number"
>> 10 would e.g. be defined as
>>
>>  D1 $ D0 $ Sz
>>
>> I wondered if it would be possible replace the expression above by a
>> heterogeneous list like
>>
>>  [D1,D0]
>>
>> so I tried to define
>>
>>  data Digit = forall a b.(Digits a, Digits (b a)) => Digit (a -> b a)
>>
>> Loading this into ghci yields:
>>
>> :t Digit D0
>>
>> :1:0:
>>Ambiguous type variable `a' in the constraint:
>>  `Digits a' arising from a use of `Digit' at :1:0-7
>>Probable fix: add a type signature that fixes these type variable(s)
>>
>> Removing the type constraints in the definition of "Digit":
>>
>>  data Digit = forall a b.Digit (a -> b a)
>>
>> makes it work like this:
>>
>>  :t Digit D0
>>  Digit D0 :: Digit
>>
>>  :t [Digit D0, Digit D1]
>>  [Digit D0, Digit D1] :: [Digit]
>>
>> "Digit", however, is far too general (it also includes e.g. \x -> [x]), but
>> I would like it to be restricted to the Digit class.
>>
>> Any help is appreciated.
>>
>> Thanks
>>
>> Harald.
>>
>>
>> CODE:
>>
>> module Test where
>>
>> data D0 a = D0 a
>> data D1 a = D1 a
>> data D2 a = D2 a
>> data D3 a = D3 a
>> data D4 a = D4 a
>> data D5 a = D5 a
>> data D6 a = D6 a
>> data D7 a = D7 a
>> data D8 a = D8 a
>> data D9 a = D9 a
>>
>> class Digits ds where
>>d2num :: Num a => ds -> a -> a
>>
>> data Sz = Sz-- zero size
>> instance Digits Sz where
>>d2num _ acc = acc
>>
>> instance Digits ds => Digits (D0 ds) where
>>d2num dds acc = d2num (t22 dds) (10*acc)
>> instance Digits ds => Digits (D1 ds) where
>>d2num dds acc = d2num (t22 dds) (10*acc+1)
>> instance Digits ds => Digits (D2 ds) where
>>d2num dds acc = d2num (t22 dds) (10*acc+2)
>> instance Digits ds => Digits (D3 ds) where
>>d2num dds acc = d2num (t22 dds) (10*acc+3)
>> instance Digits ds => Digits (D4 ds) where
>>d2num dds acc = d2num (t22 dds) (10*acc+4)
>> instance Digits ds => Digits (D5 ds) where
>>d2num dds acc = d2num (t22 dds) (10*acc+5)
>> instance Digits ds => Digits (D6 ds) where
>>d2num dds acc = d2num (t22 dds) (10*acc+6)
>> instance Digits ds => Digits (D7 ds) where
>>d2num dds acc = d2num (t22 dds) (10*acc+7)
>> instance Digits ds => Digits (D8 ds) where
>>d2num dds acc = d2num (t22 dds) (10*acc+8)
>> instance Digits ds => Digits (D9 ds) where
>>d2num dds acc = d2num (t22 dds) (10*acc+9)
>>
>> t22 :: f x -> x
>> t22 = undefined
>>
>> --data Digit = forall a b.(Digits a, Digits (b a)) => Digit (a -> b a)
>> data Digit = forall a b.Digit (a -> b a)
>>
>> -
>>
>>
>>
>> " Ce courriel et les documents qui y sont attaches peuvent contenir des 
>> informations confidentielles. Si vous n'etes  pas le destinataire escompte, 
>> merci d'en informer l'expediteur immediatement et de detruire ce courriel  
>> ainsi que tous les documents attaches de votre systeme informatique. Toute 
>> divulgation, distribution ou copie du present courriel et des documents 
>> attaches sans autorisation prealable de son emetteur est interdite."
>>
>> " This e-mail and any attached documents may contain confidential or 
>> proprietary information. If you are not the intended recipient, please 
>> advise the sender immediately and delete this e-mail and all attached 
>> documents from your computer system. Any unauthorised disclosure, 
>> distribution or copying hereof is prohibited."
>> ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-ca

Re: [Haskell-cafe] Literal programming in Haskell with rst-literals

2008-06-23 Thread Darrin Thompson
2008/6/23 Abhay Parvate <[EMAIL PROTECTED]>:
> Hello,
>
> You might already know this, but in case you don't: there is another
> literate style:
>

I had trouble finding the docs on this, as I expected them to be in
the ghc user guide. For the record, the relevant docs are in the h98
report:

http://www.haskell.org/onlinereport/literate.html

And the wiki:

http://www.haskell.org/haskellwiki/Literate_programming

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


Re: [Haskell-cafe] What is a rigid type variable?

2008-06-23 Thread Henning Thielemann


On Mon, 23 Jun 2008, Xiao-Yong Jin wrote:


Thanks for the explanation.  I guess it's just easier for me
not to give any type signature to `go', since ghc should do
the type inference quite nicely and reliably.


If you want to stay Haskell98 'asTypeOf' can help you in similar cases.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


RE: [Haskell-cafe] expected vs inferred type confusion

2008-06-23 Thread Bayley, Alistair
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Stephen Howard
> 
> the error:
> 
> renao.hs:6:4:
> Couldn't match `HttpResponse' against `IO HttpResponse'
>   Expected type: IO HttpResponse
>   Inferred type: IO (IO HttpResponse)
> In the expression: return $ (handler session request)
> In the result of a 'do' expression: return $ (handler 
> session request)
> 
> the code:
> 
> import HttpMessage
> import HttpSession
> 
> resourceHandler :: HttpSession -> HttpRequest -> IO HttpResponse
> resourceHandler session request = do
> return $ handler session request
> where
> handler = which_handler request
> which_handler r = case request_method r of
> Get-> get_resources
> Head   -> last_modified
> Post   -> update_resources
> Put-> create_resources
> Delete -> delete_resources
> 
> 
> get_resources :: HttpSession -> HttpRequest -> IO HttpResponse
> get_resources session request = undefined
> 
> -- ... the same stubbed definition for the other handlers 
> (last_modified, etc)


Try removing the do ... return $  e.g.

> resourceHandler session request =
> handler session request
> where

Alistair
*
Confidentiality Note: The information contained in this message,
and any attachments, may contain confidential and/or privileged
material. It is intended solely for the person(s) or entity to
which it is addressed. Any review, retransmission, dissemination,
or taking of any action in reliance upon this information by
persons or entities other than the intended recipient(s) is
prohibited. If you received this in error, please contact the
sender and delete the material from any computer.
*

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


[Haskell-cafe] expected vs inferred type confusion

2008-06-23 Thread Stephen Howard
I am having issues with type signatures for the resourceHandler action 
below.  I haven't figured out what I'm doing wrong to cause the wrong 
type to be returned.  It looks like Haskell is inferring that I'm 
returning a function from this action, when from the type signature I've 
specified, that is not what I'm wanting.  The gist of the code is based 
on the request_method of the passed in HttpRequest, choose an action to 
run and pass it the needed parameters.


the error:

renao.hs:6:4:
   Couldn't match `HttpResponse' against `IO HttpResponse'
 Expected type: IO HttpResponse
 Inferred type: IO (IO HttpResponse)
   In the expression: return $ (handler session request)
   In the result of a 'do' expression: return $ (handler session request)

the code:

import HttpMessage
import HttpSession

resourceHandler :: HttpSession -> HttpRequest -> IO HttpResponse
resourceHandler session request = do
   return $ handler session request
   where
   handler = which_handler request
   which_handler r = case request_method r of
   Get-> get_resources
   Head   -> last_modified
   Post   -> update_resources
   Put-> create_resources
   Delete -> delete_resources


get_resources :: HttpSession -> HttpRequest -> IO HttpResponse
get_resources session request = undefined

-- ... the same stubbed definition for the other handlers 
(last_modified, etc)

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


Re: GSoC project blogs? (Re: [Haskell-cafe] Planet haskell)

2008-06-23 Thread Malcolm Wallace
> It would be nice to have blogs for all Haskell GSoC projects
> on Planet Haskell.

See also
http://hackage.haskell.org/trac/summer-of-code/wiki/progress2008

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


Re: Re[Haskell-cafe] [2]: Help with generalizing function

2008-06-23 Thread Jonathan Cast
On Mon, 2008-06-23 at 04:03 -0700, leledumbo wrote:
> >> Don't give up so fast !! (Note that you can't do what you asked for in
> >> Pascal either, in fact Pascal don't support n-uplet) 
> I'm not going to use n-uplet, dynamic array of array of Byte is enough.
> Though not very optimizing, I can use 2 step process:

> 1. Generate all lists (array of Byte) of length N which each element ranges
> from 0 to C.

Come now, you really think this is harder in Haskell than in Pascal?
Understanding Haskell takes a little work, granted, but then I always
thought the same was true of Pascal...

> 2. Filter which has sum=C.

Come now.  Try your browser's search engine on the standard prelude,
word by word.  You can't really expect this to be just given to you, but
you must realise that sometimes it is...

> 
> >> seems that leledumbo found a new way to force us give the answers to
> >> those homeworks LOL
> Don't worry, I'm not gonna use it because it has to be done in procedural
> way (I haven't taken Functional Programming class yet). The reason why I ask
> is I'm HOPING that if I can understand how it works, implementing the
> procedural form would be easy. I've read somewhere that functional language
> can be implemented in procedural one. In fact, GHC outputs C code.
> 
> Thanks for the answer. I'll use it to learn, it's quite difficult to switch
> from procedural to functional. I mean, in procedural it's easy to find the
> fastest solution using brute force.

Huh?  The brute force solution is usually the /slowest/ solution, even
in imperative languages.  Consider bubble sort (bogo sort if you want to
push it) vs. quick sort.

>  This can't be done in functional.

If you mean `find a brute-force solution quickly', getting to the brute
force solution is indeed usually /faster/ in a functional language (it's
usually shorter, too), because of the higher level of abstraction.  (The
same is true for other modern languages, such as Perl, Ruby, to a
certain extent Python, and soon enough (hopefully) PHP, but then it's
questionable in what way the languages (as opposed to their programming
cultures) fail to be functional in the first place).

jcc



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


Re: GSoC project blogs? (Re: [Haskell-cafe] Planet haskell)

2008-06-23 Thread Antti-Juhani Kaijanaho
(I'd rather people did not send me copies of list posts.)

On Mon, Jun 23, 2008 at 02:40:27PM +0100, Claus Reinke wrote:
> It would be nice to have blogs for all Haskell GSoC projects
> on Planet Haskell.

Any such blogs would certainly qualify.  Authors should read
http://planet.haskell.org/policy.html - and while our alias address is
out of commission, send addition requests to me or Don Stewart.

-- 
Antti-Juhani Kaijanaho, Jyväskylä, Finland
http://antti-juhani.kaijanaho.fi/newblog/
http://www.flickr.com/photos/antti-juhani/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


GSoC project blogs? (Re: [Haskell-cafe] Planet haskell)

2008-06-23 Thread Claus Reinke

It would be nice to have blogs for all Haskell GSoC projects
on Planet Haskell.

Infrequent updates (such as Neil's weekly summaries) would
be quite okay - details can always be followed up in email,
provided that interested parties are aware of them in the
first place;-)

Otherwise, we end up with little community involvement,
and questions like "wasn't there a GSoC project on X last
year? What ever happened to that?"

Claus


On Mon, Jun 23, 2008 at 06:51:09AM +0100, Jamie Brandon wrote:

I was hoping to have my summer of code blog added to planet haskell
but [EMAIL PROTECTED] no longer seems to exist. Hopefully
the owner is subscribed to this list?


It exists but seems to be broken.  Thank you for letting me know.

In the mean time, just contact myself or Don Stewart.

--
Antti-Juhani Kaijanaho, Jyväskylä, Finland
http://antti-juhani.kaijanaho.fi/newblog/
http://www.flickr.com/photos/antti-juhani/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe 


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


Re: [Haskell-cafe] What is a rigid type variable?

2008-06-23 Thread Xiao-Yong Jin
"Luke Palmer" <[EMAIL PROTECTED]> writes:

> On Mon, Jun 23, 2008 at 5:58 AM, Luke Palmer <[EMAIL PROTECTED]> wrote:
>> On Mon, Jun 23, 2008 at 3:26 AM, Xiao-Yong Jin <[EMAIL PROTECTED]> wrote:
>>> Hi all,
>>>
>>> I'm writing a short function as follows, but I'm not able to
>>> find a suitable type signature for `go'.  It uses
>>> Numeric.LinearAlgebra from hmatrix.
>>>
>>>
>>> -- | Map each element in a vector to vectors and thus form a matrix
>>> -- | row by row
>>> mapVecToMat :: (Element a, Element b) =>
>>>   (a -> Vector b) -> Vector a -> Matrix b
>>> mapVecToMat f v = fromRows $ go (d - 1) []
>>>where
>>>  d = dim v
>>>  go :: Element b => Int -> [Vector b] -> [Vector b]
>>>  go 0 vs = f (v @> 0) : vs
>>>  go !j !vs = go (j - 1) (f (v @> j) : vs)
>>
>> If you want to give a type signature for 'go', you need a GHC
>> extension called ScopeTypeVariables (IIRC).
>
> I was indeed correct on the name of this extension, but it would be no
> help to you to know this since I made a typo :-)
>
> The extension is called ScopedTypeVaraibles.
>
> You probably already know that this can be enabled with:
>
> {-# LANGUAGE ScopedTypeVariables #-}
>
> Luke

Thanks for the explanation.  I guess it's just easier for me
not to give any type signature to `go', since ghc should do
the type inference quite nicely and reliably.

X-Y
-- 
c/*__o/*
<\ * (__
*/\  <
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: ANNOUNCE: Pipe 1.0

2008-06-23 Thread Simon Marlow

Isaac Dupree wrote:

Don Stewart wrote:

Interesting.
Does it depend on an unreleased version of the process library?


by the way, is there a policy for when new versions of packages 
maintained by [EMAIL PROTECTED] are *released*?  Or do patches just collect 
in the darcs repository until they're picked up by some major release 
like GHC's?  I would tend to think that for any change nontrivial enough 
to be discussed on libraries@, why not quickly release the newer version 
with an appropriately incremented version number?


There are some further changes we've been discussing, see Duncan's message 
here:


http://www.haskell.org/pipermail/libraries/2008-May/009695.html

and I'd like to batch all these together in one release.

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


Re: [Haskell-cafe] Literal programming in Haskell with rst-literals

2008-06-23 Thread Abhay Parvate
Hello,

You might already know this, but in case you don't: there is another
literate style:

... non-code ...
\begin{code}
... code ...
\end{code}
... non-code ...

in which you do not put prefixes to each line. (In fact the standard says
somewhere it is not recommended to mix the two styles if I remember right.)

I hope I am not being redundant!
Abhay


On Sat, Jun 21, 2008 at 11:48 PM, Martin Blais <[EMAIL PROTECTED]> wrote:

>
> Hello Haskell community!
>
> I just did a marginally cool thing and I wanted to share it
> with you.
>
> "rst-literals" is a small program I wrote a while ago in
> order to write documents in reStructuredText format that
> would embed SQL code for data models in them, a form of
> literal programming for SQL if you will; I would describe my
> needs for the schema in prose, and reST literal-blocks were
> used to embed SQL code, blocks that look like this::
>
>  CLASS Employee (
> firstname VARCHAR,
> lastname VARCHAR
>  )
>
> I wrote the script to be entirely generic: it parses the
> reST documents using the docutils code and outputs only the
> literal-blocks, with indentation removed; you can then run
> your favourite interpreter/compiler on the result (in that
> case, psql to initialize a database).
>
> Recently, while experimenting with Haskell, I started using
> both the literal (.lhs) and non-literal (.hs) styles of
> Haskell input, and I found the literal style a bit
> unpleasant to use, in particular, I don't like to have to
> prefix every line of code I write, despite the help that
> Emacs' haskell-mode provides.
>
> So I tried pulling a similar trick and embedding Haskell
> code in literal-blocks within reST documents, extracting
> that code using rst-literals, and it turns out that it works
> like a charm. Here is an example makefile for doing this::
>
>  .SUFFIXES: .rst .hs
>
>  all: chap6
>
>  .rst.hs:
>  rst-literals $< > $@
>
>  chap6: chap6.hs
>  ghc --make chap6.hs
>
> An example reST document with some embedded Haskell code
> follows this email. Note that since rst-literals is using
> the docutils parser, you can make use of all of the
> recursive reST syntax, sections, bulleted items and much
> more. Only the literal-blocks are extracted, anywhere they
> appear. You can also easily process the reST source into
> HTML pages or LaTeX documents using the tools that come with
> docutils.
>
> You can find rst-literals here:
> http://furius.ca/pubcode/
>
> Enjoy,
>
>
>
>
> --
> Martin
>
> P.S. If there is a way to output cpp-like directives for
> GHC, like "#line  ", it would be easy to
> modify rst-literals to generate those, so that compilation
> errors could refer to the source reST document instead of
> the extracted source.
>
>
>
> chap6.hs:
> --
>
> ===
>   Exercises from Hutton book, Chapter 6
> ===
>
> .. contents::
> ..
>1  Introduction
>2  Exercise 1
>3  Exercise 2
>4  Exercise 3
>5  Exercise 4
>6  Exercise 5
>7  Exercise 6
>
>
> Introduction
> 
>
> Bla bla bla blablablablablabla bla bla blabla. Bla bla bla
> blablablablablabla bla bla blabla. Bla bla bla blablablablablabla bla
> bla blabla. Bla bla bla blablablablablabla bla bla blabla. Bla bla bla
> blablablablablabla bla bla blabla. Bla bla bla blablablablablabla bla
> bla blabla.
>
>
> Exercise 1
> ==
> ::
>
>  myexp :: Int -> Int -> Int
>  myexp b 0 = 1
>  myexp b (n+1) = b * (myexp b n)
>
>
> Exercise 2
> ==
>
> (Exercise 2 consisted in derivations, so we mark the literal
> blocks as another type of block with "#!example", so that
> they don't get included in the output when only the
> "default" literal blocks get extracted. See rst-literals
> docstring for details.)
>
> Length::
>
>#!example
>1 + (length [2, 3])
>1 + 1 + (length [3])
>1 + 1 + (1)
>3
>
> Drop::
>
>  #!example
>  drop 3 [1, 2, 3, 4, 5]
>  [] ++ drop 3 [2, 3, 4, 5]
>  [] ++ [] ++ drop 3 [3, 4, 5]
>  [] ++ [] ++ [] ++ [4, 5]
>  [4, 5]
>
> Init::
>
>  #!example
>  init [1, 2, 3]
>  [1] ++ init [2, 3]
>  [1] ++ [2] ++ init [3]
>  [1] ++ [2] ++ []
>  [1, 2]
>
>
> Exercise 3
> ==
>
> These are alternate versions of the example functions defined in the
> text::
>
>  and' :: [Bool] -> Bool
>  and' [x] = x
>  and' (x:xs) = x && and' xs
>
>  concat' :: [[a]] -> [a]
>  concat' [] = []
>  concat' (x:xs) = x ++ concat' xs
>
>  replicate' :: Int -> a -> [a]
>  replicate' 0 x = []
>  replicate' (n+1) x = (x : replicate' n x)
>
>  select' :: [a] -> Int -> a
>  select' (x:xs) 0 = x
>  select' (x:xs) (n+1) = select' xs n
>
>  elem' :: Eq a => a -> [a] -> Bool
>  elem' _ [] = False
>  elem' y (x:xs) | x == y = True
> | otherwise = elem' y xs
>
> Exercise 4
> ==
>
> The exercise asked to implement a function to merge two lists::
>
>  merge :: Ord a => [a] -> [a] -> [a]
>  merge xs 

Re: Re[Haskell-cafe] [2]: Help with generalizing function

2008-06-23 Thread leledumbo

>> Don't give up so fast !! (Note that you can't do what you asked for in
>> Pascal either, in fact Pascal don't support n-uplet) 
I'm not going to use n-uplet, dynamic array of array of Byte is enough.
Though not very optimizing, I can use 2 step process:
1. Generate all lists (array of Byte) of length N which each element ranges
from 0 to C.
2. Filter which has sum=C.

>> seems that leledumbo found a new way to force us give the answers to
>> those homeworks LOL
Don't worry, I'm not gonna use it because it has to be done in procedural
way (I haven't taken Functional Programming class yet). The reason why I ask
is I'm HOPING that if I can understand how it works, implementing the
procedural form would be easy. I've read somewhere that functional language
can be implemented in procedural one. In fact, GHC outputs C code.

Thanks for the answer. I'll use it to learn, it's quite difficult to switch
from procedural to functional. I mean, in procedural it's easy to find the
fastest solution using brute force. This can't be done in functional.
-- 
View this message in context: 
http://www.nabble.com/Help-with-generalizing-function-tp18063291p18066861.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


Re: Re[Haskell-cafe] [2]: Help with generalizing function

2008-06-23 Thread leledumbo

>> Don't give up so fast !! (Note that you can't do what you asked for in
>> Pascal either, in fact Pascal don't support n-uplet) 
I'm not going to use n-uplet, dynamic array of array of Byte is enough.
Though not very optimizing, I can use 2 step process:
1. Generate all lists (array of Byte) of length N which each element ranges
from 0 to C.
2. Filter which has sum=C.

>> seems that leledumbo found a new way to force us give the answers to
>> those homeworks LOL
Don't worry, I'm not gonna use it because it has to be done in procedural
way (I haven't taken Functional Programming class yet). The reason why I ask
is I'm HOPING that if I can understand how it works, implementing the
procedural form would be easy. I've read somewhere that functional language
can be implemented in procedural one. In fact, GHC outputs C code.

Thanks for the answer. I'll use it to learn, it's quite difficult to switch
from procedural to functional. I mean, in procedural it's easy to find the
fastest solution using brute force. This can't be done in functional.
-- 
View this message in context: 
http://www.nabble.com/Help-with-generalizing-function-tp18063291p18066860.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


Re: [Haskell-cafe] ANNOUNCE: Pipe 1.0

2008-06-23 Thread Isaac Dupree

Don Stewart wrote:

Interesting.
Does it depend on an unreleased version of the process library?


by the way, is there a policy for when new versions of packages 
maintained by [EMAIL PROTECTED] are *released*?  Or do patches just collect 
in the darcs repository until they're picked up by some major release 
like GHC's?  I would tend to think that for any change nontrivial enough 
to be discussed on libraries@, why not quickly release the newer version 
with an appropriately incremented version number?


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


Re[2]: [Haskell-cafe] Help with generalizing function

2008-06-23 Thread Bulat Ziganshin
Hello Chaddai,

Monday, June 23, 2008, 1:42:25 PM, you wrote:

>> I give up %-|, I'll go back to Pascal instead. Thanks for your answers.

> findAllAns 0 0 = [[]]
> findAllAns 0 s = []
> findAllAns n s = [ x:xs | x <- [0..s], xs <- findAllAns (n - 1) (s - x) ]

seems that leledumbo found a new way to force us give the answers to
those homeworks LOL




-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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


Re: [Haskell-cafe] Help with generalizing function

2008-06-23 Thread Chaddaï Fouché
2008/6/23 leledumbo <[EMAIL PROTECTED]>:
>
> I give up %-|, I'll go back to Pascal instead. Thanks for your answers.

Don't give up so fast !! (Note that you can't do what you asked for in
Pascal either, in fact Pascal don't support n-uplet)

A recursive way to do it is :

findAllAns 0 0 = [[]]
findAllAns 0 s = []
findAllAns n s = [ x:xs | x <- [0..s], xs <- findAllAns (n - 1) (s - x) ]


For all those little questions that bug you, you'll get your answers
faster by asking on the #haskell channel on irc.freenode.org .

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


[Haskell-cafe] Re: "C" buffer suggestions??

2008-06-23 Thread Galchin, Vasili
Basically I want to model POSIX async io "aiocb"(
http://uw714doc.sco.com/en/man/html.5/aiocb.5.html) in Haskell .. in
particular the aiocb field "aio_buf"!

Kind regards, Vasili

On Sun, Jun 22, 2008 at 1:47 AM, Galchin, Vasili <[EMAIL PROTECTED]>
wrote:

> Hello,
>
> I want to model an I/O read/write buffer in Haskell and marshall down
> into ANSI C.
>
> 1) ByteString? Or Ptr Word8?
>
> 2) What are example values of the types in 1)?
>
>
> Kind regards, Vasili
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Safe way to parse arguments?

2008-06-23 Thread Malcolm Wallace
> > I'm wondering how usually you parse command line arguments
> > list safely.
> >
> > Prelude.read: no parse
> 
> It's generally not a good idea to call 'read' on user data.

There is (at least one) proper parsing library intended as a direct
replacement for Read:

http://www.cs.york.ac.uk/fp/polyparse/haddock/Text-Parse.html

The basic idea is that the function 'parse' replaces 'read', and to use
it at any specific type T:

(runParser parse) :: String -> (Either String T, String)

You get back either an error message or the value, along with the
remaining unparsed text.  Instances of the Parse class are defined for
all Prelude types, and you can easily derive instances for any of your
own types, using the DrIFT tool.  Parse is assumed to be an inverse of
Show, that is, the derived instances of Parse will read back a
canonically derived Show value.

Another benefit of using a real parser library is that you can plumb
together several parsers quickly if you need to.  e.g.
runParser (exactly 3 parse) :: String -> (Either String [T], String)

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


Re: [Haskell-cafe] Help with generalizing function

2008-06-23 Thread leledumbo

I give up %-|, I'll go back to Pascal instead. Thanks for your answers.
-- 
View this message in context: 
http://www.nabble.com/Help-with-generalizing-function-tp18063291p18065206.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


Re: [Haskell-cafe] number-parameterized types and heterogeneous lists

2008-06-23 Thread Alfonso Acosta
Inspired in Oleg's ideas, I implemented the packages type-level and
parameterized-data (which includes number-parameterized vectors).


To get an idea about how they work you might want to read their
haddock documentation in hackage:

http://hackage.haskell.org/cgi-bin/hackage-scripts/package/type-level
http://hackage.haskell.org/cgi-bin/hackage-scripts/package/parameterized-data

You can get their darcs repositories (including some minor updates) from:

darcs get http://code.haskell.org/type-level
darcs get http://code.haskell.org/parameterized-data

On Fri, Jun 20, 2008 at 8:01 AM, Harald ROTTER <[EMAIL PROTECTED]> wrote:
>
> Dear Haskellers,
>
> after reading Oleg Kiselyov's paper on number-parameterized types I started
> to play around with
> the class Digits that encodes decimal numbers in types. The "typed number"
> 10 would e.g. be defined as
>
>  D1 $ D0 $ Sz
>
> I wondered if it would be possible replace the expression above by a
> heterogeneous list like
>
>  [D1,D0]
>
> so I tried to define
>
>  data Digit = forall a b.(Digits a, Digits (b a)) => Digit (a -> b a)
>
> Loading this into ghci yields:
>
> :t Digit D0
>
> :1:0:
>Ambiguous type variable `a' in the constraint:
>  `Digits a' arising from a use of `Digit' at :1:0-7
>Probable fix: add a type signature that fixes these type variable(s)
>
> Removing the type constraints in the definition of "Digit":
>
>  data Digit = forall a b.Digit (a -> b a)
>
> makes it work like this:
>
>  :t Digit D0
>  Digit D0 :: Digit
>
>  :t [Digit D0, Digit D1]
>  [Digit D0, Digit D1] :: [Digit]
>
> "Digit", however, is far too general (it also includes e.g. \x -> [x]), but
> I would like it to be restricted to the Digit class.
>
> Any help is appreciated.
>
> Thanks
>
> Harald.
>
>
> CODE:
>
> module Test where
>
> data D0 a = D0 a
> data D1 a = D1 a
> data D2 a = D2 a
> data D3 a = D3 a
> data D4 a = D4 a
> data D5 a = D5 a
> data D6 a = D6 a
> data D7 a = D7 a
> data D8 a = D8 a
> data D9 a = D9 a
>
> class Digits ds where
>d2num :: Num a => ds -> a -> a
>
> data Sz = Sz-- zero size
> instance Digits Sz where
>d2num _ acc = acc
>
> instance Digits ds => Digits (D0 ds) where
>d2num dds acc = d2num (t22 dds) (10*acc)
> instance Digits ds => Digits (D1 ds) where
>d2num dds acc = d2num (t22 dds) (10*acc+1)
> instance Digits ds => Digits (D2 ds) where
>d2num dds acc = d2num (t22 dds) (10*acc+2)
> instance Digits ds => Digits (D3 ds) where
>d2num dds acc = d2num (t22 dds) (10*acc+3)
> instance Digits ds => Digits (D4 ds) where
>d2num dds acc = d2num (t22 dds) (10*acc+4)
> instance Digits ds => Digits (D5 ds) where
>d2num dds acc = d2num (t22 dds) (10*acc+5)
> instance Digits ds => Digits (D6 ds) where
>d2num dds acc = d2num (t22 dds) (10*acc+6)
> instance Digits ds => Digits (D7 ds) where
>d2num dds acc = d2num (t22 dds) (10*acc+7)
> instance Digits ds => Digits (D8 ds) where
>d2num dds acc = d2num (t22 dds) (10*acc+8)
> instance Digits ds => Digits (D9 ds) where
>d2num dds acc = d2num (t22 dds) (10*acc+9)
>
> t22 :: f x -> x
> t22 = undefined
>
> --data Digit = forall a b.(Digits a, Digits (b a)) => Digit (a -> b a)
> data Digit = forall a b.Digit (a -> b a)
>
> -
>
>
>
> " Ce courriel et les documents qui y sont attaches peuvent contenir des 
> informations confidentielles. Si vous n'etes  pas le destinataire escompte, 
> merci d'en informer l'expediteur immediatement et de detruire ce courriel  
> ainsi que tous les documents attaches de votre systeme informatique. Toute 
> divulgation, distribution ou copie du present courriel et des documents 
> attaches sans autorisation prealable de son emetteur est interdite."
>
> " This e-mail and any attached documents may contain confidential or 
> proprietary information. If you are not the intended recipient, please advise 
> the sender immediately and delete this e-mail and all attached documents from 
> your computer system. Any unauthorised disclosure, distribution or copying 
> hereof is prohibited."
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Help with generalizing function

2008-06-23 Thread Luke Palmer
On Mon, Jun 23, 2008 at 6:30 AM, leledumbo <[EMAIL PROTECTED]> wrote:
> I've successfully create a function to return lists of N-ple that satisfy the
> following function:
> x1 + x2 + x3 + ... + xN = C
> But unfortunately, it's not generic. The N is supposed to be an input, too.
> I don't know how to make a dynamic N-ple (is it possible anyway?).
> Currently, here's the implementation:
> [code]
> findAllAns c = [ (x1,x2,x3,x4,x5) |
>x1 <- [0..c],
>x2 <- [0..c],
>x3 <- [0..c],
>x4 <- [0..c],
>x5 <- [0..c],
>x1 + x2 + x3 + x4 + x5 == c
>  ]
> [/code]

You will not be able to do this with a straight list comprehension
without using recursion.  It may help you to know that:

[ e | x <- as, y <- bs ]   -- for any expression e

Is equivalent to

concat [ [ e | y <- bs ] | x <- as ]

That is a way commas in list comprehensions can be factored out.

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


Re: [Haskell-cafe] Planet haskell

2008-06-23 Thread Antti-Juhani Kaijanaho
On Mon, Jun 23, 2008 at 06:51:09AM +0100, Jamie Brandon wrote:
> I was hoping to have my summer of code blog added to planet haskell
> but [EMAIL PROTECTED] no longer seems to exist. Hopefully
> the owner is subscribed to this list?

It exists but seems to be broken.  Thank you for letting me know.

In the mean time, just contact myself or Don Stewart.

--
Antti-Juhani Kaijanaho, Jyväskylä, Finland
http://antti-juhani.kaijanaho.fi/newblog/
http://www.flickr.com/photos/antti-juhani/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] number-parameterized types and heterogeneous lists

2008-06-23 Thread Luke Palmer
On Mon, Jun 23, 2008 at 6:50 AM, Harald ROTTER <[EMAIL PROTECTED]> wrote:
> Hello,
>
> sorry for the late answer, I was off for the weekend :-)
>
> The paper "Number-parameterized types" by Oleg Kielyov is located at
>
>  http://okmij.org/ftp/papers/number-parameterized-types.pdf
>
> It impressively shows what one can do with Haskell's type system.
> What I am after is the replacement of a "chain" of digits, like e.g.
>  D1 $ D0 $ D0 $ Sz
> by a list
>  [D1,D0,D0]
> so I can effectively use list operations on those "typed numbers". I also
> wonder if there is some kind of
> "generalized" foldr such that, e.g.
>  D1 $ D0 $ D0 $ Sz = specialFoldr ($) Sz [D1,D0,D0]
> I think that this foldr must be some "special" foldr that augments the data
> type of the result in each foldr step.
> Would this be possible or am I just chasing phantoms ?

Mostly I believe you are.  What you are describing is firmly in the
realm of dependent types, far beyond Haskell's type system. See
Epigram or Agda for languages which have attempted to tackle this
problem.

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


Re: [Haskell-cafe] Help with generalizing function

2008-06-23 Thread leledumbo

>> tuples may contain any combination of types, use lists instead
I think so, too.

>> You can use <- in a list comprehension or list "do"-block to select a
>> single list from a list of lists.
Is it related with my question? I mean, instead of extracting, I need to
construct lists.
-- 
View this message in context: 
http://www.nabble.com/Help-with-generalizing-function-tp18063291p18064396.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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