[Haskell-cafe] implicit parameters THANK YOU!

2005-03-21 Thread S. Alexander Jacobson
I just discovered implicit parameters.  To everyone involved with 
making them, THANK YOU.  They are blazingly useful/powerful for server 
handler style libraries where you want to make a veriety of local 
environment information available to the handlers without burdening 
the handlers with a big dictionary object to carry around.  FANTASTIC.

That being said, they so powerful they are proabably easy to abuse. 
Could those experienced with this feature provide warnings about 
possible problems with overuse?

I see so many places I think I could make HAppS code nicer using this 
feature that I am concerned about making mistakes.

-Alex-
__
S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] tuple and HList

2005-03-21 Thread David Menendez
Frederik Eaton writes:

> > You need to swap the arguments to TCons...
> > 
> > data TCons l a = TCons !l a
> > 
> > Then:
> > 
> > instance Functor (TCons (TCons HNil a)) where
> >fmap f (TCons (TCons HNil x) y) = TCons (TCons HNil (f x)) y)
> 
> How does one solve this problem in general, i.e. when the arguments to
> a type are in the wrong order for an instance that one wants to
> declare?

In general? You either make a newtype or change the definition of the
original type.

> Someone on the haskell IRC channel mentioned that if you could derive
> instances for partially applied type synonyms then one could just
> make a dummy synonym with the arguments in the right order, but that
> doesn't appear to be premitted. The other question is why isn't it
> permitted.

As I understand it, the reason you can't do instances for partially
applied type synonyms is because it makes instance selection ambiguous.

For example:

instance Functor ((,) a) where fmap f (x,y) = (x, f y)

type RevPair a b = (b,a)

instance Functor (RevPair a) where fmap f (x,y) = (f x, y)

If I write 'fmap f (x,y)', do I get '(f x, y)' or '(x, f y)'?
-- 
David Menendez <[EMAIL PROTECTED]> 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Linux device drivers

2005-03-21 Thread Iavor Diatchki
Hello,
There are no storage drivers at the moment.  Actually part of the
motivation for implementing the networking stuff was so that we can
avoid doing that at least for the time being.
-Iavor


On Mon, 21 Mar 2005 01:32:19 -0500 (Eastern Standard Time), S.
Alexander Jacobson <[EMAIL PROTECTED]> wrote:
> Very very cool.
> Has anyone written any storage drivers?
> If there is already TCP, has someone written an iscsi (RFC3720)
> driver?
> 
> -Alex-
> 
> 
> On Mon, 21 Mar 2005, Donald Bruce Stewart wrote:
> 
> > dons:
> >> alex:
> >>> Wow!  Did you also implement tcp in Haskell?
> >
> > On this topic, the following House code looks relevant:
> >http://cvs.haskell.org/cgi-bin/cvsweb.cgi/programatica/hOp/kernel/Net/
> >
> > There's something satsifying about seeing 'instance Functor Packet' in
> > IPv4.hs ;)
> >
> >>> Does hOp or House also have the ability to write to disk?
> >>>
> >>> (With HAppS, I've gotten rid of the AMP part of LAMP, it would be
> >>> really cool to get rid of the L as well!)
> >>
> >> Sorry! By "We've got a few drivers written in Haskell", I meant
> >> "the Haskell community", not me personally :} You have the hOp and House
> >> developers to thank for this stuff.
> >>
> >>> On Mon, 21 Mar 2005, Donald Bruce Stewart wrote:
> >>>
>  mark:
> > I was wondering about the possibility of using Haskell for developing
> > device drivers that would be kernel modules for Linux. If nothing else,
> > it would be quite an educational experience for me, as I've not yet
> > experimented with either the Linux kernel or Haskell FFI, nor have I
> > had to learn how to squeeze much performance out of my Haskell code.
> >
> > Clearly, this application demands special things from the compiler and
> > the runtime. But, I'm not exactly sure what, nor how to achieve such
> > given current compilers. Does anyone have any thoughts?
> 
>  Well, it would be tricky, but fun!
> 
>  We've got a few drivers written in Haskell already (but not for Linux,
>  as far as I know). For example check out the House network stack and
>  drivers:
>    http://cvs.haskell.org/cgi-bin/cvsweb.cgi/programatica/hOp/
>  and
>    
>  http://cvs.haskell.org/cgi-bin/cvsweb.cgi/programatica/hOp/kernel/Kernel/Driver/NE2000/
> 
>  So there's heavy use of Data.Bits and Word# types - but nothing that
>  isn't fairly well established in GHC Haskell, anyway.
> 
>  Then (for GHC, anyway) you'd have to link the kernel against libHSrts.a,
>  much
>  as we do when calling Haskell from other kinds of C apps, which involves
>  compiling the C app with all the magic flags ghc normally sets up (ghc 
>  -v9
>  main.c is helpful).  Something like: ;)
> 
>  egcc -v -o a.out -DDONT_WANT_WIN32_DLL_SUPPORT main.o
>  -L/home/dons/lib/ghc-6.4 -lHStemplate-haskell -lHSCabal -lHSposix
>  -lHSposix_cbits -lHSlang -lHSmtl -lHShaskell-src -lHSunix -lHSunix_cbits
>  -lHShi -lHShaskell98 -lHSaltdata -lHSbase -lHSbase_cbits -lHSrts -lm 
>  -lgmp
>  -u GHCziBase_Izh_static_info -u GHCziBase_Czh_static_info -u
>  GHCziFloat_Fzh_static_info ...
> 
>  Then, having the kernel start up the Haskell rts (at boot would be
>  good):
>  hs_init(&argc, &argv);
>    .. do something in Haskell or C land ...
>  hs_exit();
> 
>  Then you'd could dyn load (via GHC's rts) your Haskell driver into the C
>  app, and use it, as long as you've got a nice ffi interface to pass
>  values back and forward.
> 
>  I'm sure the fun part is in the details ;)
> 
>  Cheers,
>  Don
>  ___
>  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
> >
> 
> __
> S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com
> ___
> 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] invalid character encoding

2005-03-21 Thread Glynn Clements

John Meacham wrote:

> > I'm not suggesting inventing conventions. I'm suggesting leaving such
> > issues to the application programmer who, unlike the library
> > programmer, probably has enough context to be able to reliably
> > determine the correct encoding in any specific instance.
> 
> But the whole point of Foreign.C.String is to interface to existing C
> code. And one of the most common conventions of said interfaces is to
> represent strings in the current locale, Which is why locale honoring
> conversion routines are useful. 

My point is that most C functions which accept or return char*s will
work regardless of whether those char*s can be decoded according to
the current locale. E.g.

while (d = readdir(dir), d)
{
stat(d->d_name, &st);
...
}

will stat() every filename in the directory regardless of whether or
not the filenames are valid in the locale's encoding.

The Haskell equivalent using FilePath (i.e. String),
getDirectoryContents etc currently only works because the char* <->
String conversions are hardcoded to ISO-8859-1, which is infallible
and reversible. If it used e.g. UTF-8, it would fail on any filename
which wasn't valid UTF-8 even though it never actually needs to know
the string of characters which the filename represents.

The same applies to reading filenames from argv[] and passing them to
open() etc. This is one of the most common idioms in Unix programming,
and it doesn't care about encodings at all. Again, it would cease to
work reliably in Haskell if the automatic char* <-> String conversions
in getArgs etc started using the locale.

I'm not arguing about *how* char* <-> String conversions should be
performed so much as arguing about *whether* these conversions should
be performed. The conversion issues are only problems because the
conversions are being done at all.

-- 
Glynn Clements <[EMAIL PROTECTED]>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] invalid character encoding

2005-03-21 Thread Ross Paterson
On Sun, Mar 20, 2005 at 04:34:12AM +, Ian Lynagh wrote:
> On Sun, Mar 20, 2005 at 01:33:44AM +, [EMAIL PROTECTED] wrote:
> > On Sat, Mar 19, 2005 at 07:14:25PM +, Ian Lynagh wrote:
> > > Is there anything LC_CTYPE can be set to that will act like C/POSIX but
> > > accept 8-bit bytes as chars too?
> > 
> > en_GB.iso88591 (or indeed any .iso88591 locale) will match the old
> > behaviour (and the GHC behaviour).
> 
> This works for me with en_GB.iso88591 (or en_GB), but not en_US.iso88591
> (or en_US). My /etc/locale.gen contains:
> 
> en_GB ISO-8859-1
> en_GB.ISO-8859-15 ISO-8859-15
> en_GB.UTF-8 UTF-8
> 
> So is there anything that /always/ works?

Since systems may have no locale other than C/POSIX, no.

> > Yes, I don't see how to avoid this when using mbtowc() to do the
> > conversion: it makes no distinction between a bad byte sequence and an
> > incomplete one.
> 
> Perhaps you could use mbrtowc instead?

Indeed.  Thanks for pointing it out.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] tuple and HList

2005-03-21 Thread Frederik Eaton
> You need to swap the arguments to TCons...
> 
> data TCons l a = TCons !l a
> 
> Then:
> 
> instance Functor (TCons (TCons HNil a)) where
>fmap f (TCons (TCons HNil x) y) = TCons (TCons HNil (f x)) y)

How does one solve this problem in general, i.e. when the arguments to
a type are in the wrong order for an instance that one wants to
declare? Someone on the haskell IRC channel mentioned that if you
could derive instances for partially applied type synonyms then one
could just make a dummy synonym with the arguments in the right order,
but that doesn't appear to be premitted. The other question is why
isn't it permitted.

Frederik

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


Re: [Haskell-cafe] tuple and HList

2005-03-21 Thread Keean Schupke
David Menendez wrote:
   instance Functor ((,) a) where
   fmap f (x,y) = (x, f y)
 


If we get rid of '(,)' and redefine '(a,b)' as sugar for 'TCons a (TCons
b HNil)' (or whatever), then there is no way to declare the above instance. I don't think that's a deal-killer, but it is a disadvantage.
 

You need to swap the arguments to TCons...
data TCons l a = TCons !l a
Then:
instance Functor (TCons (TCons HNil a)) where
   fmap f (TCons (TCons HNil x) y) = TCons (TCons HNil (f x)) y)
   Keean.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe