Re: [Haskell-cafe] MySQL and HDBC?

2009-01-23 Thread Sebastian Sylvan
2009/1/23 Galchin, Vasili vigalc...@gmail.com

 Hello,

  Real World Haskell seems to say that the abstraction layer HDBC
 doesn't support MySQL. If so, in what sense doesn't HDBC support
 MySQL??


It doesn't have a MySQL  backend. However, it does have an ODBC backend
which should work fine with MySQL.


-- 
Sebastian Sylvan
+44(0)7857-300802
UIN: 44640862
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Does readFile /proc/mounts hang for you?

2009-01-23 Thread Brandon S. Allbery KF8NH

On 2009 Jan 21, at 21:13, Thomas DuBuisson wrote:

ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0x77470b70) = -1 ENOTTY
(Inappropriate ioctl for device)


This is just the test for buffering:  terminal-like devices (TCGETS)  
are line buffered, others are block buffered.



select(4, [3], [], NULL, {0, 0})= 0 (Timeout)
select(4, [3], [], NULL, {134, 217727} unfinished ...


I'm too rusty on any sort of low level work to draw meaning out of
this without work, but...

See that failed ioctl that seems to be completely ignored, right
before hanging in our 'select' call?
And see the select call that says 'wait 134 seconds'?  If you wait it
out you get:


The ioctl() is a red herring, as stated above.  I think the real  
problem is that files in /proc are all simulated by the kernel, and  
the simulation probably doesn't work very well if they're opened non- 
blocking and select()ed on.


--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
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] Employment

2009-01-23 Thread George Pollard

On Fri, 2009-01-23 at 16:19 +1100, Toby Hutton wrote:
 On Fri, Jan 23, 2009 at 11:56 AM, Jonathan Cast
 jonathancc...@fastmail.fm wrote:
 
  Not really.  My company *advertises* for Haskell developers, and then
  when they come in to interview, informs them that the code base is
  actually written in Perl.  Works, too --- we have several Haskellers
  working here.  If all you care about is the quality of the developers,
  and not their productivity once you've got them, you don't actually
need
  to let them use Haskell after the interview is over...

 I saw this trick recently for a job advertised locally to me, in
 Melbourne.  I was initially pretty excited that someone in this city
 was actually advertising for Haskell programmers, until I realised
 they needed to be good at Javascript and Perl so they could work on
 their web apps.  Argh, I didn't bother applying.

I think I saw the same advertisement; unfortunately it was on a joint
Australasian website so I was in the wrong country anyway :)

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


Re: [Haskell-cafe] Why monoids will abide...

2009-01-23 Thread Brandon S. Allbery KF8NH

On 2009 Jan 22, at 10:09, Andrew Wagner wrote:
See, that's the kind of name we need!  
StructureWithAssociativeOperationAndIdentity -- make both the  
mathematicians AND the non-mathematicians mad!


SimpleArithmetic (you have numbers and a single arithmetic  
operation on them).  You can play similar games with the mathematical  
concepts of groups and rings.  (But you get into trouble with magmas  
and semigroups.)


In any case, my response to bikeshedding these days is to present a  
fait accompli so people can just get stuff done instead of waiting for  
many-legs-and-no-brain (otherwise known as a committee) to do  
something.  The math terms have at least the advantage of already  
being well defined.  Yes, this means you get to learn some abstract  
math --- but then, you're going to be faced with that the first time  
you encounter (or need!) type-level Peano numbers anyway.  Or fix/mfix  
(least defined fixed point).


--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon universityKF8NH


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


[Haskell-cafe] Liskell installation configuration problems in Cygwin on Windows XP Professional, Service Pack 2

2009-01-23 Thread Benjamin L . Russell
Yesterday, I downloaded Darcs 2.2 and Liskell for Windows XP
Professional, Service Pack 2, but the following error message appeared
when I ran ./Setup.lhs configure in Cygwin:

Configuring liskell-0.1...
Setup.lhs: At least the following dependencies are missing:
ghc-paths -any

Does anybody know how this issue should be resolved?

-- Benjamin L. Russell
-- 
Benjamin L. Russell  /   DekuDekuplex at Yahoo dot com
http://dekudekuplex.wordpress.com/
Translator/Interpreter / Mobile:  +011 81 80-3603-6725
Furuike ya, kawazu tobikomu mizu no oto. 
-- Matsuo Basho^ 

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


[Haskell-cafe] Re: Liskell installation configuration problems in Cygwin on Windows XP Professional, Service Pack 2

2009-01-23 Thread Benjamin L . Russell
On Fri, 23 Jan 2009 18:10:16 +0900, Benjamin L.Russell
dekudekup...@yahoo.com wrote:

Yesterday, I downloaded Darcs 2.2 and Liskell for Windows XP
Professional, Service Pack 2, but the following error message appeared
when I ran ./Setup.lhs configure in Cygwin:

Configuring liskell-0.1...
Setup.lhs: At least the following dependencies are missing:
ghc-paths -any

Does anybody know how this issue should be resolved?

-- Benjamin L. Russell

I forgot to mention that I downloaded Liskell by following the
instructions on CFruhwirth's Weblog: Liskell standalone (see
http://blog.clemens.endorphin.org/2009/01/liskell-standalone.html).  I
also posted this question yesterday in a comment there, but nobody has
responded yet.

Incidentally, the Liskell home page at http://liskell.org/ seems to be
down (instead of the original site, an advertisement page, with the
error message Sorry, access forbidden, error 403, appears at the
bottom of the displayed site).

Does anybody know what's up (or down?) with Liskell?

-- Benjamin L. Russell
-- 
Benjamin L. Russell  /   DekuDekuplex at Yahoo dot com
http://dekudekuplex.wordpress.com/
Translator/Interpreter / Mobile:  +011 81 80-3603-6725
Furuike ya, kawazu tobikomu mizu no oto. 
-- Matsuo Basho^ 

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


Re: [Haskell-cafe] MySQL and HDBC?

2009-01-23 Thread Duncan Coutts
On Fri, 2009-01-23 at 08:06 +, Sebastian Sylvan wrote:
 
 
 2009/1/23 Galchin, Vasili vigalc...@gmail.com
 Hello,
 
  Real World Haskell seems to say that the abstraction
 layer HDBC doesn't support MySQL. If so, in what sense doesn't
 HDBC support
 MySQL??
 
 It doesn't have a MySQL  backend. However, it does have an ODBC
 backend which should work fine with MySQL.

This was uploaded to hackage yesterday:

http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HDBC-mysql-0.1

You might like to test it and give feedback to the author.

Duncan

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


Re: [Haskell-cafe] Re: Liskell installation configuration problems in Cygwin on Windows XP Professional, Service Pack 2

2009-01-23 Thread Neil Mitchell
Hi Benjamin,

Try:

cabal install ghc-paths

If you want to install packages manually you can also get it from
http://hackage.haskell.org

Thanks

Neil

On Fri, Jan 23, 2009 at 9:16 AM, Benjamin L. Russell
dekudekup...@yahoo.com wrote:
 On Fri, 23 Jan 2009 18:10:16 +0900, Benjamin L.Russell
 dekudekup...@yahoo.com wrote:

Yesterday, I downloaded Darcs 2.2 and Liskell for Windows XP
Professional, Service Pack 2, but the following error message appeared
when I ran ./Setup.lhs configure in Cygwin:

Configuring liskell-0.1...
Setup.lhs: At least the following dependencies are missing:
ghc-paths -any

Does anybody know how this issue should be resolved?

-- Benjamin L. Russell

 I forgot to mention that I downloaded Liskell by following the
 instructions on CFruhwirth's Weblog: Liskell standalone (see
 http://blog.clemens.endorphin.org/2009/01/liskell-standalone.html).  I
 also posted this question yesterday in a comment there, but nobody has
 responded yet.

 Incidentally, the Liskell home page at http://liskell.org/ seems to be
 down (instead of the original site, an advertisement page, with the
 error message Sorry, access forbidden, error 403, appears at the
 bottom of the displayed site).

 Does anybody know what's up (or down?) with Liskell?

 -- Benjamin L. Russell
 --
 Benjamin L. Russell  /   DekuDekuplex at Yahoo dot com
 http://dekudekuplex.wordpress.com/
 Translator/Interpreter / Mobile:  +011 81 80-3603-6725
 Furuike ya, kawazu tobikomu mizu no oto.
 -- Matsuo Basho^

 ___
 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] Re: MySQL and HDBC?

2009-01-23 Thread Gour
 Sebastian == Sebastian Sylvan syl...@student.chalmers.se writes:

Sebastian It doesn't have a MySQL backend. However, it does have an
Sebastian ODBC backend which should work fine with MySQL.

http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HDBC-mysql


Sincerely,
Gour


-- 

Gour  | Zagreb, Croatia  | GPG key: C6E7162D



pgpN67sXfGpTx.pgp
Description: PGP signature
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: how to implement daemon start and stop directives?

2009-01-23 Thread Eugene Kirpichov
2009/1/23 Ertugrul Soeylemez e...@ertes.de:
 Luke Palmer lrpal...@gmail.com wrote:

 On Thu, Jan 22, 2009 at 9:04 AM, Ertugrul Soeylemez e...@ertes.de wrote:

  Sometimes this is inevitable, but I've never seen a case, where
  IORefs couldn't be replaced by a more elegant State/StateT-based
  solution.  And if you need to do multi-threading, Chans, MVars and
  semaphores are better anyway.

 Please define better.  For the function in question, what advantages
 do they give us?

 It gives you thread-safety for free, which IORefs don't give you.  It's
 the same purpose, the same amount of code, but threadsafe by concept.
 Of course, for simple variables, IORefs will likely be thread-safe as
 well, but there is no guarantee here.  With MVars you have that
 guarantee.


 Just to be clear, I wouldn't dare argue that IORefs can do everything
 MVars and TVars can do.  I'm just perplexed why you say MVars and
 TVars are better, when an IORef does the trick just fine for our
 function.

 What I'm saying is:  Even if IORefs suffice, why would you want to use
 them, if MVar does the job as well and likely better?


  There is no reason to prefer an IORef over an MVar to signal
  something to another thread.

 Well, I usually don't go here, but benchmarks show that IORefs are the
 fastest of any of the mutable variable primitives, by at least a
 factor of 2.  I wish I remembered where I saw that.

 Yes, that's a good point, but I think, you can safely disregard that for
 signalling a thread to quit.


  By the way, IORefs are by themselves not thread-safe.  You need to
  use a special function, when using it in a multi-threaded manner.

 You mean atomicModifyIORef?

 Yes.


 IORefs *are* thread-safe by themselves: you will not make your program
 segfault by using them in a multithreaded program.  So it all comes
 down to invariants.  IORefs have no synchronization concepts, so code
 like:

 x - readIORef ref
 writeIORef ref (x+1)

 Is not threadsafe by most standards.  That doesn't mean IORefs
 themselves are not threadsafe, just that you have to be careful how
 you use them.

 That's exactly my point.  In the above case they do just the same, but
 need more care.


 And I will reiterate:  *in this case* the use of IORef is fully
 encapsulated in this function and *is threadsafe!* Which is the basis
 of my argument: in imperative code, when you can limit the scope of an
 IORef to a small abstraction that is threadsafe, there is no advantage
 of TVars or MVars over them.  I don't think they deserve bad style
 sledgehammer.  (An instance of use the right tool for the job)

 daemon :: IO () - IO (IO ())
 daemon action = do
 stopvar - newIORef False
 let run = do
   stop - readIORef stopvar
   if stop then return () else (action  run)
 forkIO run
 return (writeIORef stopvar True)

 In this case, it's simply a coincidence that it's safe.  It's because
 you're using an IORef Bool, and because writes to a Bool variable are
 atomic on virtually all platforms.  An Integer may already fail to be
 thread-safe.  You need more care and the payoff is zero.  If you still
 insist on using IORefs, at least use the atomic function above, but that
 destroys the little performance benefit of using IORefs, unless GHC does
 some intelligent optimization here, which I doubt.

This would be the case if the IORef was unboxed, but it is boxed, so
writing an IORef is actually writing a pointer to a thunk; here, Bool
and Integer have no difference at all. However, I don't know whether
GHC makes pointer writes atomic on all platforms (Java does, so it's
at least doable).



 Greets,
 Ertugrul.


 --
 nightmare = unsafePerformIO (getWrongWife = sex)
 http://blog.ertes.de/


 ___
 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] MySQL and HDBC?

2009-01-23 Thread Galchin, Vasili
ok .. thank you.

Vasili


On Fri, Jan 23, 2009 at 3:23 AM, Duncan Coutts
duncan.cou...@worc.ox.ac.ukwrote:

 On Fri, 2009-01-23 at 08:06 +, Sebastian Sylvan wrote:
 
 
  2009/1/23 Galchin, Vasili vigalc...@gmail.com
  Hello,
 
   Real World Haskell seems to say that the abstraction
  layer HDBC doesn't support MySQL. If so, in what sense doesn't
  HDBC support
  MySQL??
 
  It doesn't have a MySQL  backend. However, it does have an ODBC
  backend which should work fine with MySQL.

 This was uploaded to hackage yesterday:

 http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HDBC-mysql-0.1

 You might like to test it and give feedback to the author.

 Duncan


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


Re: [Haskell-cafe] Employment

2009-01-23 Thread Brent Yorgey
On Thu, Jan 22, 2009 at 04:57:56PM -0800, Jonathan Cast wrote:
 On Tue, 2009-01-20 at 19:14 +, Andrew Coppin wrote:
  Jonathan Cast wrote:
   On Mon, 2009-01-19 at 21:04 +, Andrew Coppin wrote:
 
   I mean, heck, *I* use Haskell at work - and I'm not even supposed to be 
   coding things!
 
   /me feels slightly relieved, if you'll forgive my saying so :)
 
  Damn... I didn't think I was *that* bad at using Haskell? o_O
 
 You have expressed continued bafflement on any number of subjects that
 have been repeatedly explained to you, so yes.

I call Andrew's bluff.  The continued bafflement is just to get
attention.  He's probably not *that* bad at using Haskell. =)

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


[Haskell-cafe] Re: Is it possible to model eventually consistent side effects?

2009-01-23 Thread Ertugrul Soeylemez
Daryoush Mehrtash dmehrt...@gmail.com wrote:

 I am trying to figure out if there is a way to model cloud computing
 computations in Haskell.

 My specific problems is that in cloud computing, as in Amazon
 WebServices, side effects (writes to storage, simple database, queue)
 follow the eventually consistent model.  Which means even if your
 writes succeeds, it may or may not be immediately available for reads.
 Each call to the services may also temporarily experience network
 errors or end-system unavailability.  Virtual machines can mount a
 local disk that does offers consistent storage, but the storage wont
 survive a reboot (after a crash).

 I am trying to find out if I can model computation (and its
 compositions) where I can hide reliability and consistency issues. And
 also be able to reason about a computation to make sure no combination
 of errors and inconsistencies would break my logic.

 Is it possible?  If so is there a good starting point?

Haskell implements cheap concurrency, with which you can do these kinds
of things.  There are a few communication and synchronization concepts.
You may be particularly interested in software transactional memory
(STM) [1].  However, unfortunately we have not approached network
transparency yet, so you cannot use this with cloud computing for now.
However, of course nothing stops you from implementing the communication
between the hosts yourself.  This shouldn't be too difficult.

[1] http://haskell.org/haskellwiki/Software_transactional_memory


Greets,
Ertugrul.


-- 
nightmare = unsafePerformIO (getWrongWife = sex)
http://blog.ertes.de/


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


[Haskell-cafe] Generic typeclass for converting between types

2009-01-23 Thread John Goerzen
Hi folks,

I've been thinking today that I frequently need to convert data beween
types:

 * Between various numeric types

 * Between various calendar types (both within the new calendar
   system, and between the old and new)

 * Marshalling data back and forth to a database in HDBC

It's hard to remember all the functions to use to do these.  I often
resort to a chart I made for numeric conversions.

It occurs to me that it would be nice to be able to

  (convert (5.8::Double))::Int

or

  (convert calendarTime)::ZonedTime

So, the first question is: does something like this exist already?
I'm not aware of it, but I'm not sure how to search either.

I'm thinking of something like the below.  With a little magic, it's
quite possible to make errors easy to generate in the safe fashion
(for instance, when converting from String to Integer using reads).

{-# LANGUAGE MultiParamTypeClasses #-}
import Control.Monad.Error

type ConvertResult a = Either ConvertError a

class Convertible a b where
safeConvert :: a - ConvertResult b

instance Convertible Int Double where
safeConvert = return . fromIntegral
instance Convertible Double Int where
safeConvert = return . truncate -- could do bounds checking here
instance Convertible Integer Double where
safeConvert = return . fromIntegral
instance Convertible Double Integer where
safeConvert = return . truncate

convert :: Convertible a b = a - b
convert inp = case safeConvert inp of
Left e - error (show e)
Right x - x

-- rudimentary error type for this example

data ConvertError = ConvertError {
  sourceValue :: String,
  errorMessage :: String
}
deriving (Eq, Read, Show)

instance Error ConvertError where
strMsg x = ConvertError (unknown) x

The other option is to use an approach more like I have in HDBC.  In
HDBC, there is a direct need to encapsulate data for transport, so
I've got this:

class (Show a) = SqlType a where
toSql :: a - SqlValue
safeFromSql :: SqlValue - FromSqlResult a

data SqlValue = SqlString String 
  | SqlByteString B.ByteString
  | SqlWord32 Word32
  | SqlWord64 Word64
  ... many more 

... 

instance SqlType Int32 where
sqlTypeName _ = Int32
toSql = SqlInt32
safeFromSql (SqlString x) = read' x
safeFromSql (SqlByteString x) = (read' . byteString2String) x
safeFromSql (SqlInt32 x) = return x
safeFromSql (SqlInt64 x) = return . fromIntegral $ x

The advantage of this is that if you've got a whole slew of types and
you're going to be converting between all of them (for instance,
numeric types), if you turn on -Wall the compiler will help you know
when your safeFromSql instance doesn't convert everything.  The
disadvantage is that the type system doesn't enforce whether or not it
is even possible to convert certain things (for instance, a TimeOfDay
to a Char), and so we have to return a Left for those.

Any thoughts?

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


Re: [Haskell-cafe] Generic typeclass for converting between types

2009-01-23 Thread Magnus Therning
On Fri, Jan 23, 2009 at 3:01 PM, John Goerzen jgoer...@complete.org wrote:
 Hi folks,

 I've been thinking today that I frequently need to convert data beween
 types:

  * Between various numeric types

  * Between various calendar types (both within the new calendar
   system, and between the old and new)

  * Marshalling data back and forth to a database in HDBC

 It's hard to remember all the functions to use to do these.  I often
 resort to a chart I made for numeric conversions.

Not the type of response you want, but would you publish that chart
somewhere, please ;-)

/M

-- 
Magnus Therning(OpenPGP: 0xAB4DFBA4)
magnus@therning.org  Jabber: magnus@therning.org
http://therning.org/magnus identi.ca|twitter: magthe
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: how to implement daemon start and stop directives?

2009-01-23 Thread Ertugrul Soeylemez
Eugene Kirpichov ekirpic...@gmail.com wrote:

  daemon :: IO () - IO (IO ())
  daemon action = do
  stopvar - newIORef False
  let run = do
stop - readIORef stopvar
if stop then return () else (action  run)
  forkIO run
  return (writeIORef stopvar True)
 
  In this case, it's simply a coincidence that it's safe.  It's
  because you're using an IORef Bool, and because writes to a Bool
  variable are atomic on virtually all platforms.  An Integer may
  already fail to be thread-safe.  You need more care and the payoff
  is zero.  If you still insist on using IORefs, at least use the
  atomic function above, but that destroys the little performance
  benefit of using IORefs, unless GHC does some intelligent
  optimization here, which I doubt.

 This would be the case if the IORef was unboxed, but it is boxed, so
 writing an IORef is actually writing a pointer to a thunk; here, Bool
 and Integer have no difference at all. However, I don't know whether
 GHC makes pointer writes atomic on all platforms (Java does, so it's
 at least doable).

It will likely work, but the compiler is not required to make pointer
writes atomic, and it would be an enormous performance hit.  The pointer
write is more likely atomic by platform, not by the code, but even there
I would be very careful, because it may be not the case for SMP systems.
And you know what happens, when a pointer race condition occurs.

The selection between MVar and IORef is essentially a security or
performance question.  Especially for daemons I would rather choose
security.  MVar gives you that security with _the same amount of code_.

And to prove that IORefs do lead to a pointer race condition and hence
are insecure, try the following code:

  main :: IO ()
  main = do
ref - newIORef False
forkIO $ forever $ modifyIORef ref not
forever $ readIORef ref = print

It crashes for me.  I'm using GHC 6.10.1 on an Athlon 64 X2 (32 bits
system).  The error message reads:

  test: internal error: schedule: invalid what_next field
  (GHC version 6.10.1 for i386_unknown_linux)
  Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug


Greets,
Ertugrul.


-- 
nightmare = unsafePerformIO (getWrongWife = sex)
http://blog.ertes.de/


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


Re: [Haskell-cafe] Generic typeclass for converting between types

2009-01-23 Thread John Goerzen
Magnus Therning wrote:
 On Fri, Jan 23, 2009 at 3:01 PM, John Goerzen jgoer...@complete.org wrote:
 Hi folks,

 I've been thinking today that I frequently need to convert data beween
 types:

  * Between various numeric types

  * Between various calendar types (both within the new calendar
   system, and between the old and new)

  * Marshalling data back and forth to a database in HDBC

 It's hard to remember all the functions to use to do these.  I often
 resort to a chart I made for numeric conversions.
 
 Not the type of response you want, but would you publish that chart
 somewhere, please ;-)

Sure :-)

http://book.realworldhaskell.org/read/using-typeclasses.html#numerictypes.conversion

You might also find these useful:

Typeclass instances for numeric types:
http://book.realworldhaskell.org/read/using-typeclasses.html#numerictypes.typeclasses

Chart of numeric functions:
http://book.realworldhaskell.org/read/using-typeclasses.html#numerictypes.funcs

-- John

 
 /M
 

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


Re: [Haskell-cafe] MySQL and HDBC?

2009-01-23 Thread Chris Waterson

On Jan 23, 2009, at 1:23 AM, Duncan Coutts wrote:


On Fri, 2009-01-23 at 08:06 +, Sebastian Sylvan wrote:



2009/1/23 Galchin, Vasili vigalc...@gmail.com
   Hello,

Real World Haskell seems to say that the abstraction
   layer HDBC doesn't support MySQL. If so, in what sense doesn't
   HDBC support
   MySQL??

It doesn't have a MySQL  backend. However, it does have an ODBC
backend which should work fine with MySQL.


This was uploaded to hackage yesterday:

http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HDBC-mysql-0.1

You might like to test it and give feedback to the author.


I would very much appreciate feedback.

I'm still working with John Goerzen (who has been extremely helpful)  
to iron our some details, see [1] for a list of issues that you should  
be aware of before you start doing anything too serious.


thanks!
chris

[1] http://www.maubi.net/~waterson/hacks/hdbc-mysql.html
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: how to implement daemon start and stop directives?

2009-01-23 Thread Gleb Alexeyev

Ertugrul Soeylemez wrote:

And to prove that IORefs do lead to a pointer race condition and hence
are insecure, try the following code:

  main :: IO ()
  main = do
ref - newIORef False
forkIO $ forever $ modifyIORef ref not
forever $ readIORef ref = print

It crashes for me.  I'm using GHC 6.10.1 on an Athlon 64 X2 (32 bits
system).  The error message reads:

  test: internal error: schedule: invalid what_next field
  (GHC version 6.10.1 for i386_unknown_linux)
  Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug


Interesting. Looks like a bug in the single-threaded runtime to me: I 
can reproduce this crash only when compiling without the `-threaded' flag.


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


Re: [Haskell-cafe] Haskell mode for Emacs question

2009-01-23 Thread Peter Verswyvelen
looks like a neath editor. too bad on windows you don't get anti aliased
fonts (I guess it uses an old J2SE or something?)
at first sight I was not able to find Haskell support in the freely
downloadable version. is this available in the commercial version?


On Thu, Jan 22, 2009 at 6:50 PM, John A. De Goes j...@n-brain.net wrote:


 Not that you're looking to switch editors, but if you want something a
 little more hassle-free:

http://www.n-brain.net/unashots/Haskell/ErrorHighlighting.png

 Regards,

 John


 On Jan 22, 2009, at 10:17 AM, Peter Verswyvelen wrote:

  I have a silly problem.

 I'm using Emacs with the Haskell mode extension on Windows

 I have a source file in say

 c:/foo/src/main.hs

 main.hs is importing some other modules in that same src directory

 When I invoke GHCi from within Emacs, the first thing it does is

 :cd c:/foo

 and then

 :load src/main.hs

 But of course GHCi won't find the imported modules now, since the current
 directory is wrong.

 If I type in GHCi

 :cd src
 :load main.hs

 then it compiles fine.

 Does anyone have an idea why Emacs or the Haskell mode is switching to the
 parent directory of src instead of src itself, and how to fix this?

 Thanks a lot,
 Peter

 ___
 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] Haskell mode for Emacs question

2009-01-23 Thread John A. De Goes


No, Haskell support in the free version too. However, you'll have to  
add the tools to compile .hs files in the Tools menu. You can pipe  
the output to directly highlight errors/warnings in the document  
(which is what's done in the screenshot below), because the editor  
understands what GHC errors/warnings look like.


Regards,

John

http://www.n-brain.net|877-376-2724 x 101

On Jan 23, 2009, at 10:45 AM, Peter Verswyvelen wrote:

looks like a neath editor. too bad on windows you don't get anti  
aliased fonts (I guess it uses an old J2SE or something?)


at first sight I was not able to find Haskell support in the freely  
downloadable version. is this available in the commercial version?



On Thu, Jan 22, 2009 at 6:50 PM, John A. De Goes j...@n-brain.net  
wrote:


Not that you're looking to switch editors, but if you want something  
a little more hassle-free:


   http://www.n-brain.net/unashots/Haskell/ErrorHighlighting.png

Regards,

John


On Jan 22, 2009, at 10:17 AM, Peter Verswyvelen wrote:

I have a silly problem.

I'm using Emacs with the Haskell mode extension on Windows

I have a source file in say

c:/foo/src/main.hs

main.hs is importing some other modules in that same src directory

When I invoke GHCi from within Emacs, the first thing it does is

:cd c:/foo

and then

:load src/main.hs

But of course GHCi won't find the imported modules now, since the  
current directory is wrong.


If I type in GHCi

:cd src
:load main.hs

then it compiles fine.

Does anyone have an idea why Emacs or the Haskell mode is switching  
to the parent directory of src instead of src itself, and how to fix  
this?


Thanks a lot,
Peter

___
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] MySQL and HDBC?

2009-01-23 Thread Duncan Coutts
On Fri, 2009-01-23 at 03:54 -0600, Galchin, Vasili wrote:

 On Fri, Jan 23, 2009 at 3:23 AM, Duncan Coutts
 duncan.cou...@worc.ox.ac.uk wrote:
 
 This was uploaded to hackage yesterday:
 
 
 http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HDBC-mysql-0.1
 
 You might like to test it and give feedback to the
 author.


 ooops ... cabal install HDBC-mysql doesn't work ??
 
 Vasili

Vasili, it's really no good telling me this, especially since you did
not cc the author or haskell-cafe. I am not the author of the package.
And even if I were you have provided no details on what goes wrong.

I'm sure it was not your intention, but to some people your response
would sound demanding and unhelpful, possibly even rude. Make sure that
when you do contact the author that you send them something that they
will find helpful.

So when you email the author make sure you provide full details about
what you did and about the environment you are using, eg platform, ghc
version, where your mysql libraries are installed, what version they are
etc.

I would guess that the most likely problem is that you do not have the
mysql development package installed. It should provide the mysql_config
program. If that is not the problem then contact the package author with
the full details.

Duncan

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


[Haskell-cafe] mapM_ - Monoid.Monad.map

2009-01-23 Thread Henning Thielemann


 I always considered the monad functions with names ending on '_' a 
concession to the IO monad. Would you need them for any other monad than 
IO? For self-written monads you would certainly use a monoid instead of 
monadic action, all returning (), but IO is a monad. (You could however 
wrap (newtype Output = Output (IO ())) and define a Monoid instance on 
Output.)
 However our recent Monoid discussion made me think about mapM_, 
sequence_, and friends. I think they could be useful for many monads if 
they would have the type:

 mapM_ :: (Monoid b) = (a - m b) - [a] - m b
  I expect that the Monoid instance of () would yield the same efficiency 
as todays mapM_ and it is also safer since it connects the monadic result 
types of the atomic and the sequenced actions. There was a recent 
discussion on the topic:

 http://neilmitchell.blogspot.com/2008/12/mapm-mapm-and-monadic-statements.html
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] mapM_ - Monoid.Monad.map

2009-01-23 Thread Thomas Davie


On 23 Jan 2009, at 21:50, Henning Thielemann wrote:



I always considered the monad functions with names ending on '_' a  
concession to the IO monad. Would you need them for any other monad  
than IO? For self-written monads you would certainly use a monoid  
instead of monadic action, all returning (), but IO is a monad. (You  
could however wrap (newtype Output = Output (IO ())) and define a  
Monoid instance on Output.)
However our recent Monoid discussion made me think about mapM_,  
sequence_, and friends. I think they could be useful for many monads  
if they would have the type:

mapM_ :: (Monoid b) = (a - m b) - [a] - m b
 I expect that the Monoid instance of () would yield the same  
efficiency as todays mapM_ and it is also safer since it connects  
the monadic result types of the atomic and the sequenced actions.  
There was a recent discussion on the topic:

http://neilmitchell.blogspot.com/2008/12/mapm-mapm-and-monadic-statements.html


Of note btw, these don't need Monad at all...

sequence :: Applicative f = [f a] - f [a]
sequence = foldr (liftA2 (:)) (pure [])

mapA :: (Traversable t, Applicative f) = (a - f b) - t a - f (t b)
mapA = (fmap . fmap) sequence fmap

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


[Haskell-cafe] Generalizing a filter-making function

2009-01-23 Thread Dominic Espinosa
Novice question here. Sorry if the post is wordy.

In the following code (which doesn't actually compile as-is), I'm trying
to generalize these 'make*Filter' functions into a single 'makeFilter'
function. However, I can't get the types to work right.

Foo is a tuple type on which a large number of accessor functions are
defined. All of them have type Foo - Int, Foo - String, or Foo
- [a] (so far).

I tried defining 'Query' using exsistential types instead, but had
difficulty with 'escaped type variables' when I tried to write a
generalized 'makeFilter' function.

The general point of makeFilter is to take as parameters a Query, a
value, a comparison function, and then return a function (Foo - Bool).
This returned function takes as its argument an object of type Foo,
applies the function 'q' to it, compares that value to 'val', and
finally returns a Bool. 

Later on in the program, a list of these filter functions is to be used
with a list of Foo objects, to determine which Foo objects satisfy all
of the filters.

Advice would be greatly appreciated.

--- code ---

data Query a = Query { query_identifier :: String, query_func :: (Foo - a) }

makeIntFilter :: Query Int - Int - (Int - Int - Bool) 
 - (Foo - Bool)
makeIntFilter q val cmp = (\k - val `cmp` (query_func q $ k))

makeStringFilter :: Query String - String - (String - String - Bool) 
- (Foo - Bool)
makeStringFilter q val cmp =  (\k - val `cmp` (query_func q $ k))

-- ??? broken, and the 'cmp' argument is thrown away, which seems wrong
makeMemberFilter :: Eq a = Query [a] - a - (a - a - a) 
- (Foo - Bool)
makeMemberFilter q val cmp =(\k - val `elem` (query_func q $ k))

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


Re: [Haskell-cafe] MySQL and HDBC?

2009-01-23 Thread david48
On Fri, 2009-01-23 at 03:54 -0600, Galchin, Vasili wrote:

 ooops ... cabal install HDBC-mysql doesn't work ??

for what it's worth, calbal install hdbc-mysql worked on my office's pc.
( kubuntu 8.10 )
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] mapM_ - Monoid.Monad.map

2009-01-23 Thread Joachim Breitner
Hi,

Am Freitag, den 23.01.2009, 21:50 +0100 schrieb Henning Thielemann:
   However our recent Monoid discussion made me think about mapM_, 
 sequence_, and friends. I think they could be useful for many monads if 
 they would have the type:
   mapM_ :: (Monoid b) = (a - m b) - [a] - m b
I expect that the Monoid instance of () would yield the same efficiency 
 as todays mapM_

will it? This is based on a naive, not well-founded understanding of
haskell evaluation, but looking at
 instance Monoid () where
   mempty= ()
   _ `mappend` _ = ()
   mconcat _ = ()
I’d assume that evaluating
 mapM_ (putStrLn) lotsOfLargeStrings
with your proposed mapM_ will leave a thunk equivalent to
 () `mappend` () `mappend` () `mappend`...
in memory until the mapM_ has completely finished, where each () is
actually an unevalutated thunk that still has a reference to one of the
elements in the lotsOfLargeStrings list.

Greetings,
Joachim

-- 
Joachim nomeata Breitner
  mail: m...@joachim-breitner.de | ICQ# 74513189 | GPG-Key: 4743206C
  JID: nome...@joachim-breitner.de | http://www.joachim-breitner.de/
  Debian Developer: nome...@debian.org


signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Employment

2009-01-23 Thread Bartosz Wójcik
On Monday 19 January 2009 23:26:09 Sittampalam, Ganesh wrote:
 We (Credit Suisse) have Haskell developers in both London and NY,
 although the page only listed NY (I've now corrected it).

If CS had Haskell positions in Wroclaw, Poland I'd apply for it!
Best,
Bartek


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


Re: [Haskell-cafe] mapM_ - Monoid.Monad.map

2009-01-23 Thread Dan Doel
On Friday 23 January 2009 3:50:18 pm Henning Thielemann wrote:
   I always considered the monad functions with names ending on '_' a
 concession to the IO monad. Would you need them for any other monad than
 IO? For self-written monads you would certainly use a monoid instead of
 monadic action, all returning (), but IO is a monad. (You could however
 wrap (newtype Output = Output (IO ())) and define a Monoid instance on
 Output.)
   However our recent Monoid discussion made me think about mapM_,
 sequence_, and friends. I think they could be useful for many monads if
 they would have the type:
   mapM_ :: (Monoid b) = (a - m b) - [a] - m b
I expect that the Monoid instance of () would yield the same efficiency
 as todays mapM_ and it is also safer since it connects the monadic result
 types of the atomic and the sequenced actions. There was a recent
 discussion on the topic:

What is your proposed definition of the new mapM_? For instance:

  mapM_ f = foldr (liftM2 mappend) (return mempty)

Has exactly the same problem as mapM for the situations you'd actually want to 
use it (roughly, it's not monadically 'tail recursive'). You could instead 
have:

  mapM_ f = foldr () (return mempty)

which does have the right behavior, but it doesn't naturally have the type you 
give above, and always returns mempty, which isn't much more useful than 
always returning ().

mapM_ is also useful in ST (perhaps not surprising) and strict State. It 
should be useful in other monads in which = implies a strict sequencing of 
evaluation, as it's the difference between:

  nonTail (x:xs) = do a - foo x
  b - nonTail xs -- overflows for long lists
  return $ f a b

and:

  tail (x:xs) = do foo x
   tail xs

Even if f doesn't even look at its arguments, it leads to stack overflows for 
long lists in certain monads.

You can, of course, write a 'tail recursive' mapM by using an Endo m 
accumulator (to preseve ordering), and that might work out well enough, but I 
haven't thought much about it. In any case, I have a hard time believing IO is 
the *only* monad where you might want to write a loop purely for its side 
effects, but maybe I'm off the mark.

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


Re: [Haskell-cafe] mapM_ - Monoid.Monad.map

2009-01-23 Thread George Pollard
On Fri, 2009-01-23 at 21:30 +, Joachim Breitner wrote:
 Hi,
 
 Am Freitag, den 23.01.2009, 21:50 +0100 schrieb Henning Thielemann:
However our recent Monoid discussion made me think about mapM_, 
  sequence_, and friends. I think they could be useful for many monads if

  they would have the type:
mapM_ :: (Monoid b) = (a - m b) - [a] - m b
 I expect that the Monoid instance of () would yield the same
efficiency 
  as todays mapM_
 
 will it? This is based on a naive, not well-founded understanding of
 haskell evaluation, but looking at
  instance Monoid () where
  mempty= ()
  _ `mappend` _ = ()
  mconcat _ = ()
 I’d assume that evaluating
  mapM_ (putStrLn) lotsOfLargeStrings
 with your proposed mapM_ will leave a thunk equivalent to
  () `mappend` () `mappend` () `mappend`...
 in memory until the mapM_ has completely finished, where each () is
 actually an unevalutated thunk that still has a reference to one of the
 elements in the lotsOfLargeStrings list.

Perhaps this is why the Monoid instance for () in GHC's source has the
comment should this be strict? :)

signature.asc
Description: PGP signature


rcmAttmntahOV2C
Description: micalg/pgp-sha1
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] How to define an operation in terms of itself (but of different type)?

2009-01-23 Thread Olex P
Hello Haskellers!
It's probably a simple question but I can't find a proper solution...
Suppose we have a class Vector which overloads (+) operation. I'd like to
represent a Matrix data type as a set of vectors:

data Matrix3 = M3 !Vector3 !Vector3 !Vector3

In this case (+) for matrices could be implemented as:

 (M3 r11 r12 r13) + (M3 r21 r22 r23) = M3 (r11 + r21) (r12 + r22) (r13 +
r23)

But GHC says about ambiguous occurrence. I don't understand why because it's
should be pretty clear that rows are vectors and (+) has to be vector type
as well. I could use Vector.+ instead but it doesn't look good.
Probably I'm missing something. Any ideas?

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


Re: [Haskell-cafe] Employment

2009-01-23 Thread Krzysztof Skrzętnicki
There are quite a few people with working Haskell knowledge in Wroclaw. I'm
sure many of my colleagues (from University of Wroclaw:
http://www.ii.uni.wroc.pl/ http://www.ii.uni.wroc.pl/cms/)
know Haskell and I think would enjoy working with it.

All best

Christopher Skrzętnicki

On Fri, Jan 23, 2009 at 23:31, Bartosz Wójcik bar...@sudety.it wrote:

 On Monday 19 January 2009 23:26:09 Sittampalam, Ganesh wrote:
  We (Credit Suisse) have Haskell developers in both London and NY,
  although the page only listed NY (I've now corrected it).

 If CS had Haskell positions in Wroclaw, Poland I'd apply for it!
 Best,
 Bartek


 ___
 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] How to define an operation in terms of itself (but of different type)?

2009-01-23 Thread Miguel Mitrofanov
Seems like all telepath are on vacation, so you would have to show the  
code.


On 24 Jan 2009, at 01:15, Olex P wrote:


Hello Haskellers!
It's probably a simple question but I can't find a proper solution...
Suppose we have a class Vector which overloads (+) operation. I'd  
like to represent a Matrix data type as a set of vectors:


data Matrix3 = M3 !Vector3 !Vector3 !Vector3

In this case (+) for matrices could be implemented as:

 (M3 r11 r12 r13) + (M3 r21 r22 r23) = M3 (r11 + r21) (r12 + r22)  
(r13 + r23)


But GHC says about ambiguous occurrence. I don't understand why  
because it's should be pretty clear that rows are vectors and (+)  
has to be vector type as well. I could use Vector.+ instead but it  
doesn't look good.

Probably I'm missing something. Any ideas?

Cheers,
Oleksandr.
___
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] How to define an operation in terms of itself (but of different type)?

2009-01-23 Thread Jonathan Cast
On Sat, 2009-01-24 at 01:30 +0300, Miguel Mitrofanov wrote:
 Seems like all telepath are on vacation,

Now, now, you didn't let enough time elapse to know that for sure.

jcc


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


Re: [Haskell-cafe] Generalizing a filter-making function

2009-01-23 Thread Ross Mellgren

makeFilter :: (b - b - Bool) - (a - b) - b - a - Bool
makeFilter (==) proj expected = (expected ==) . proj

makeEqFilter :: Eq b = (a - b) - b - a - Bool
makeEqFilter = makeFilter (==)

Then you have a foo:

data Foo = Foo { fooA :: String, fooB :: Int }

foos = [Foo a 1, Foo b 2]

filter (makeEqFilter fooA 1) foos

and so on.

Though this is not really buying you all that much over

filter ((1 ==) . fooA) foos

Or for storing

data Query a = Query String (a - Bool)

let myQuery = Query Test if fst is 1 ((1 ==) . fst)

...

filter myQuery foos

Does this help?

-Ross

On Jan 23, 2009, at 4:20 PM, Dominic Espinosa wrote:


Novice question here. Sorry if the post is wordy.

In the following code (which doesn't actually compile as-is), I'm  
trying

to generalize these 'make*Filter' functions into a single 'makeFilter'
function. However, I can't get the types to work right.

Foo is a tuple type on which a large number of accessor functions are
defined. All of them have type Foo - Int, Foo - String, or Foo
- [a] (so far).

I tried defining 'Query' using exsistential types instead, but had
difficulty with 'escaped type variables' when I tried to write a
generalized 'makeFilter' function.

The general point of makeFilter is to take as parameters a Query, a
value, a comparison function, and then return a function (Foo -  
Bool).

This returned function takes as its argument an object of type Foo,
applies the function 'q' to it, compares that value to 'val', and
finally returns a Bool.

Later on in the program, a list of these filter functions is to be  
used

with a list of Foo objects, to determine which Foo objects satisfy all
of the filters.

Advice would be greatly appreciated.

--- code ---

data Query a = Query { query_identifier :: String, query_func ::  
(Foo - a) }


makeIntFilter :: Query Int - Int - (Int - Int - Bool)
- (Foo - Bool)
makeIntFilter q val cmp = (\k - val `cmp` (query_func q $ k))

makeStringFilter :: Query String - String - (String - String -  
Bool)

   - (Foo - Bool)
makeStringFilter q val cmp =  (\k - val `cmp` (query_func q $ k))

-- ??? broken, and the 'cmp' argument is thrown away, which seems  
wrong

makeMemberFilter :: Eq a = Query [a] - a - (a - a - a)
   - (Foo - Bool)
makeMemberFilter q val cmp =(\k - val `elem` (query_func q $ k))

___
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] How to define an operation in terms of itself (but of different type)?

2009-01-23 Thread Miguel Mitrofanov

On 24 Jan 2009, at 01:35, Jonathan Cast wrote:


On Sat, 2009-01-24 at 01:30 +0300, Miguel Mitrofanov wrote:

Seems like all telepath are on vacation,


Now, now, you didn't let enough time elapse to know that for sure.


They're always on vacation when you need one.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to define an operation in terms of itself (but of different type)?

2009-01-23 Thread Luke Palmer
2009/1/23 Olex P hoknam...@gmail.com

 Hello Haskellers!
 It's probably a simple question but I can't find a proper solution...
 Suppose we have a class Vector which overloads (+) operation. I'd like to
 represent a Matrix data type as a set of vectors:

 data Matrix3 = M3 !Vector3 !Vector3 !Vector3

 In this case (+) for matrices could be implemented as:

  (M3 r11 r12 r13) + (M3 r21 r22 r23) = M3 (r11 + r21) (r12 + r22) (r13 +
 r23)

 But GHC says about ambiguous occurrence. I don't understand why because
 it's should be pretty clear that rows are vectors and (+) has to be vector
 type as well. I could use Vector.+ instead but it doesn't look good.
 Probably I'm missing something. Any ideas?


I'm am seeing an image.  It's a... a Vector class, with an operation (+).
 Oh, he's with another one though.  It's the Num class.  Oh they're fighting
over the (+).  Vector is trying to take it from Num, but Num isn't letting
go.

Why doesn't Vector see that there is a whole pile of operations neglected in
the corner, like (^+^), (.+.).  He just really wants that (+), huh...

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


Re: [Haskell-cafe] How to define an operation in terms of itself (but of different type)?

2009-01-23 Thread Olex P
Well if telepaths on vacation...

class Vector v where
(^+^)   :: v - v - v

data Vector3 = V3 !Double !Double !Double

instance Vector Vector3 where
(V3 x1 y1 z1) ^+^ (V3 x2 y2 z2) = V3 (x1 + x2) (y1 + y2) (z1 + z2)

class Matrix m where
(^+^) :: m - m - m

data Matrix3 = M3 !Vector3 !Vector3 !Vector3

instance Matrix Matrix3 where
(M3 r11 r12 r13) ^+^ (M3 r21 r22 r23) = M3 (r11 ^+^ r21)
  (r12 ^+^
r22)
  (r13 ^+^
r23)

Hope this is better :)
So yeah... r11 ^+^ r21 just doesn't work.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to define an operation in terms of itself (but of different type)?

2009-01-23 Thread minh thu
2009/1/23 Olex P hoknam...@gmail.com:
 Well if telepaths on vacation...

 class Vector v where
 (^+^)   :: v - v - v

 data Vector3 = V3 !Double !Double !Double

 instance Vector Vector3 where
 (V3 x1 y1 z1) ^+^ (V3 x2 y2 z2) = V3 (x1 + x2) (y1 + y2) (z1 + z2)

 class Matrix m where
 (^+^) :: m - m - m

 data Matrix3 = M3 !Vector3 !Vector3 !Vector3

 instance Matrix Matrix3 where
 (M3 r11 r12 r13) ^+^ (M3 r21 r22 r23) = M3 (r11 ^+^ r21)
   (r12 ^+^
 r22)
   (r13 ^+^
 r23)

 Hope this is better :)
 So yeah... r11 ^+^ r21 just doesn't work.
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe



Luke's story about Num and a supposed Vector class is repeated here
between Vector and Matrix classes.

Either you make a class Add instanciated by both Vector and Matrix,
or you use different name for each of them.

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


Re: [Haskell-cafe] How to define an operation in terms of itself (but of different type)?

2009-01-23 Thread Dan Piponi
2009/1/23 Olex P hoknam...@gmail.com:

 class Vector v where
 (^+^)   :: v - v - v

 data Vector3 = V3 !Double !Double !Double

 instance Vector Vector3 where
 (V3 x1 y1 z1) ^+^ (V3 x2 y2 z2) = V3 (x1 + x2) (y1 + y2) (z1 + z2)

 class Matrix m where
 (^+^) :: m - m - m

 data Matrix3 = M3 !Vector3 !Vector3 !Vector3

 instance Matrix Matrix3 where
 (M3 r11 r12 r13) ^+^ (M3 r21 r22 r23) = M3 (r11 ^+^ r21)
   (r12 ^+^
 r22)
   (r13 ^+^
 r23)

 Hope this is better :)
 So yeah... r11 ^+^ r21 just doesn't work.

It works fine if you make Matrix3 an instance of Vector.
--
Dan
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] mapM_ - Monoid.Monad.map

2009-01-23 Thread Derek Elkins
On Fri, 2009-01-23 at 13:39 -0800, George Pollard wrote:
 On Fri, 2009-01-23 at 21:30 +, Joachim Breitner wrote:
  Hi,
  
  Am Freitag, den 23.01.2009, 21:50 +0100 schrieb Henning Thielemann:
 However our recent Monoid discussion made me think about mapM_, 
   sequence_, and friends. I think they could be useful for many monads if
 
   they would have the type:
 mapM_ :: (Monoid b) = (a - m b) - [a] - m b
  I expect that the Monoid instance of () would yield the same
 efficiency 
   as todays mapM_
  
  will it? This is based on a naive, not well-founded understanding of
  haskell evaluation, but looking at
   instance Monoid () where
 mempty= ()
 _ `mappend` _ = ()
 mconcat _ = ()
  I’d assume that evaluating
   mapM_ (putStrLn) lotsOfLargeStrings
  with your proposed mapM_ will leave a thunk equivalent to
   () `mappend` () `mappend` () `mappend`...
  in memory until the mapM_ has completely finished, where each () is
  actually an unevalutated thunk that still has a reference to one of the
  elements in the lotsOfLargeStrings list.
 
 Perhaps this is why the Monoid instance for () in GHC's source has the
 comment should this be strict? :)

It's easy to calculate the answer.

mempty `mappend` undefined = undefined (left identity monoid law)
The above definition doesn't meet this, similarly for the right identity
monoid law.  That only leaves one definition, () `mappend` () = () which
does indeed satisfy the monoid laws.

So the answer to the question is Yes.  Another example of making
things as lazy as possible going astray.

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


Re: [Haskell-cafe] How to define an operation in terms of itself (but of different type)?

2009-01-23 Thread minh thu
2009/1/24 Dan Piponi dpip...@gmail.com:
 2009/1/23 Olex P hoknam...@gmail.com:

 class Vector v where
 (^+^)   :: v - v - v

 data Vector3 = V3 !Double !Double !Double

 instance Vector Vector3 where
 (V3 x1 y1 z1) ^+^ (V3 x2 y2 z2) = V3 (x1 + x2) (y1 + y2) (z1 + z2)

 class Matrix m where
 (^+^) :: m - m - m

 data Matrix3 = M3 !Vector3 !Vector3 !Vector3

 instance Matrix Matrix3 where
 (M3 r11 r12 r13) ^+^ (M3 r21 r22 r23) = M3 (r11 ^+^ r21)
   (r12 ^+^
 r22)
   (r13 ^+^
 r23)

 Hope this is better :)
 So yeah... r11 ^+^ r21 just doesn't work.

 It works fine if you make Matrix3 an instance of Vector.
 --
 Dan

To paraphrase a bit, your Vector class simply means :
a type is a Vector if it provides an operation having a - a - a
has its type (and called ^+^).

The Matrix class says exactly the same thing, so don't bother
repeat that... and simply make Vector3 and Matrix3 instances
of Vector (which could then be renamed in Add or Plus or
something).

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


Re: [Haskell-cafe] How to define an operation in terms of itself (but of different type)?

2009-01-23 Thread Jonathan Cast
On Fri, 2009-01-23 at 22:58 +, Olex P wrote:
 Well if telepaths on vacation...
 
 class Vector v where
 (^+^)   :: v - v - v
 
 data Vector3 = V3 !Double !Double !Double
 
 instance Vector Vector3 where
 (V3 x1 y1 z1) ^+^ (V3 x2 y2 z2) = V3 (x1 + x2) (y1 + y2) (z1 + z2)
 
 class Matrix m where
 (^+^) :: m - m - m
 
 
 data Matrix3 = M3 !Vector3 !Vector3 !Vector3
 
 
 instance Matrix Matrix3 where
 
 (M3 r11 r12 r13) ^+^ (M3 r21 r22 r23) = M3 (r11 ^+^ r21)
   (r12
 ^+^ r22)
   (r13
 ^+^ r23)
 
 
 Hope this is better :)
 So yeah... r11 ^+^ r21 just doesn't work. 

I think you mis-understand how classes work in Haskell.  They aren't
like classes in OO languages.  They're a little bit like interfaces in
OO languages, but here we see another difference: in OO, you know an
object has a certain class, so you use that to find out what a method
name means.  In Haskell, it's the other way around: you know a method
belongs to a certain class, so you know its argument (or result) must
come from an instance of that class.  You can't re-use method names for
multiple classes, though - you have to either use different names (e.g.,
div vs. (/) in Prelude) or use a common base class.

jcc


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


Laws and partial values (was: [Haskell-cafe] mapM_ - Monoid.Monad.map)

2009-01-23 Thread roconnor

On Fri, 23 Jan 2009, Derek Elkins wrote:


mempty `mappend` undefined = undefined (left identity monoid law)
The above definition doesn't meet this, similarly for the right identity
monoid law.  That only leaves one definition, () `mappend` () = () which
does indeed satisfy the monoid laws.

So the answer to the question is Yes.  Another example of making
things as lazy as possible going astray.


I'd like to argue that laws, such as monoid laws, do not apply to partial 
values.  But I haven't thought my position through yet.


--
Russell O'Connor  http://r6.ca/
``All talk about `theft,''' the general counsel of the American Graphophone
Company wrote, ``is the merest claptrap, for there exists no property in
ideas musical, literary or artistic, except as defined by statute.''
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Error in HTTP 4.004 + CouchDB?

2009-01-23 Thread Tristan Seligmann
* Alex Ott alex...@gmail.com [2009-01-22 20:32:26 +0100]:

 
 PUT http://127.0.0.1:5984/test1/Users_ott_tmp_1_tst HTTP/1.1
 Content-Type: ...
 ...
 Host: 127.0.0.1:5984
 ...

Note that this is a valid HTTP request, according to my reading of RFC2616.
-- 
mithrandi, i Ainil en-Balandor, a faer Ambar


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


Re: Laws and partial values (was: [Haskell-cafe] mapM_ - Monoid.Monad.map)

2009-01-23 Thread Luke Palmer
On Fri, Jan 23, 2009 at 6:10 PM, rocon...@theorem.ca wrote:

 On Fri, 23 Jan 2009, Derek Elkins wrote:

  mempty `mappend` undefined = undefined (left identity monoid law)
 The above definition doesn't meet this, similarly for the right identity
 monoid law.  That only leaves one definition, () `mappend` () = () which
 does indeed satisfy the monoid laws.

 So the answer to the question is Yes.  Another example of making
 things as lazy as possible going astray.


 I'd like to argue that laws, such as monoid laws, do not apply to partial
 values.  But I haven't thought my position through yet.


Please try to change your mind.

You know how annoying it is when you are doing math, and you want to divide,
but first you have to add the provision that the denominator isn't zero.
 Saying that monoid laws do not apply to partial values, while easing the
implementation a bit, add similar provisions to reasoning.

For example, it is possible to prove that foldr mappend mempty (x:xs) =
foldr1 mappend (x:xs).  Which means that anywhere in the source where we see
the former, we can clean it up to the latter.  However, if monad laws
don't apply to partial values, then we first have to prove that none of the
(x:xs) are _|_, perhaps even that no substrings are _|_.  This is a much
more involved transformation, so much so that you probably just wouldn't do
it if you want to be correct.

Bottoms are part of Haskell's semantics; theorems and laws have to apply to
them to.  You can pretend they don't exist, but then you have to be okay
with never using an infinite data structure.  I.e. if your programs would
run just as well in Haskell as they would in a call-by-value language, then
you don't have to worry about bottoms.

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


RE: [Haskell-cafe] Current research on overlapping/closed type families?

2009-01-23 Thread Simon Peyton-Jones
Provided all the overlapping instances are supplied together, as you suggest, I 
think what you say makes perfect sense and does not threaten soundness.

But we have not yet implemented the idea yet.  First priority is to get type 
families working properly, and in conjunction with type classes.  Then we can 
move on to adding features.

Simon

| -Original Message-
| From: haskell-cafe-boun...@haskell.org [mailto:haskell-cafe-
| boun...@haskell.org] On Behalf Of Ryan Ingram
| Sent: 19 January 2009 23:24
| To: Haskell Cafe
| Subject: [Haskell-cafe] Current research on overlapping/closed type families?
|
| What's the status of overlapping/closed type families?  I'm interested
| in something like the following, which can currently be implemented in
| GHC with Oleg-magic using functional dependencies, but cannot, to my
| knowledge, be implemented with type families:
|
| data HTrue = HTrue
| data HFalse = HFalse
|
| type family IsFunction f
|
| {- not legal in GHC6.10 -}
| type instances
|IsFunction (a - b) = HTrue
|IsFunction a = HFalse
|
|   -- ryan
| ___
| 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] Current research on overlapping/closed type families?

2009-01-23 Thread Ryan Ingram
Of course.  I was just wondering if anyone was looking into the
implications of said features :)

For example, with this instance, if a is a type variable, you can't
reduce IsFunction a to HFalse, because a might be b - c for
some b, c.

Whereas in the current formulation, you can treat the declaration as a
rewrite rule without considering how variables are instantiated.  Of
course, this makes IsFunction far less useful; if you were using it
to, for example, define automatic currying and uncurrying of
n-argument functions, it matters whether the result is higher-order or
not, which is somewhat unsatisfying.

  -- ryan

On Fri, Jan 23, 2009 at 6:06 PM, Simon Peyton-Jones
simo...@microsoft.com wrote:
 Provided all the overlapping instances are supplied together, as you suggest, 
 I think what you say makes perfect sense and does not threaten soundness.

 But we have not yet implemented the idea yet.  First priority is to get type 
 families working properly, and in conjunction with type classes.  Then we can 
 move on to adding features.

 Simon

 | -Original Message-
 | From: haskell-cafe-boun...@haskell.org [mailto:haskell-cafe-
 | boun...@haskell.org] On Behalf Of Ryan Ingram
 | Sent: 19 January 2009 23:24
 | To: Haskell Cafe
 | Subject: [Haskell-cafe] Current research on overlapping/closed type 
 families?
 |
 | What's the status of overlapping/closed type families?  I'm interested
 | in something like the following, which can currently be implemented in
 | GHC with Oleg-magic using functional dependencies, but cannot, to my
 | knowledge, be implemented with type families:
 |
 | data HTrue = HTrue
 | data HFalse = HFalse
 |
 | type family IsFunction f
 |
 | {- not legal in GHC6.10 -}
 | type instances
 |IsFunction (a - b) = HTrue
 |IsFunction a = HFalse
 |
 |   -- ryan
 | ___
 | 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] Error in HTTP 4.004 + CouchDB?

2009-01-23 Thread Daniel McAllansmith
On Sat, 24 Jan 2009 14:18:24 Tristan Seligmann wrote:
 * Alex Ott alex...@gmail.com [2009-01-22 20:32:26 +0100]:
  PUT http://127.0.0.1:5984/test1/Users_ott_tmp_1_tst HTTP/1.1
  Content-Type: ...
  ...
  Host: 127.0.0.1:5984
  ...

 Note that this is a valid HTTP request, according to my reading of RFC2616.

Depends what you mean by valid.  Yes it's a valid request to receive, no an 
implementation is not compliant with RFC2616 if it issues a request like this 
to an origin server.

Have a look at section 5.1.2.  An implementation is REQUIRED to issue requests 
like this to proxies, an implementation MUST handle receiving requests like 
this, an implementation MUST use the abs_path form in requests to origin 
servers and gateways, ie

PUT /test1/Users_ott_tmp_1_tst HTTP/1.1
Host: 127.0.0.1:5984

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


Re: [Haskell-cafe] Current research on overlapping/closed type families?

2009-01-23 Thread Dan Weston

Would this then also eventually work?

data Zero
data Succ a = Succ a

type family IsFunction f

type instances
  IsFunction (a - b) = Succ (IsFunction b)
  IsFunction c= Zero


Simon Peyton-Jones wrote:

Provided all the overlapping instances are supplied together, as you suggest, I 
think what you say makes perfect sense and does not threaten soundness.

But we have not yet implemented the idea yet.  First priority is to get type 
families working properly, and in conjunction with type classes.  Then we can 
move on to adding features.

Simon

| -Original Message-
| From: haskell-cafe-boun...@haskell.org [mailto:haskell-cafe-
| boun...@haskell.org] On Behalf Of Ryan Ingram
| Sent: 19 January 2009 23:24
| To: Haskell Cafe
| Subject: [Haskell-cafe] Current research on overlapping/closed type families?
|
| What's the status of overlapping/closed type families?  I'm interested
| in something like the following, which can currently be implemented in
| GHC with Oleg-magic using functional dependencies, but cannot, to my
| knowledge, be implemented with type families:
|
| data HTrue = HTrue
| data HFalse = HFalse
|
| type family IsFunction f
|
| {- not legal in GHC6.10 -}
| type instances
|IsFunction (a - b) = HTrue
|IsFunction a = HFalse
|
|   -- ryan
| ___
| 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-cafe


Re: Laws and partial values (was: [Haskell-cafe] mapM_ - Monoid.Monad.map)

2009-01-23 Thread roconnor

Thanks for letting me reflect on this.

I assume that my final program (my final value) is always a total value. 
Anything else is an error.  Therefore, if we required relaxed monoid laws 
of the form


x `mappend` mzero = x

then we could safely substitute (x `mappend` mzero) by x without changing 
the final value (I think this true).  But the reverse substituion 
,replacing x with (x `mappend` mzero), might not be sound.  Now, I can see 
why you would prefer that the laws hold for partial values.


On Fri, 23 Jan 2009, Luke Palmer wrote:


On Fri, Jan 23, 2009 at 6:10 PM, rocon...@theorem.ca wrote:
  On Fri, 23 Jan 2009, Derek Elkins wrote:

mempty `mappend` undefined = undefined (left
identity monoid law)
The above definition doesn't meet this, similarly
for the right identity
monoid law.  That only leaves one definition, ()
`mappend` () = () which
does indeed satisfy the monoid laws.

So the answer to the question is Yes.  Another
example of making
things as lazy as possible going astray.


  I'd like to argue that laws, such as monoid laws, do not apply
  to partial values.  But I haven't thought my position through
  yet.


Please try to change your mind.  

You know how annoying it is when you are doing math, and you want to divide,
but first you have to add the provision that the denominator isn't zero.
 Saying that monoid laws do not apply to partial values, while easing the
implementation a bit, add similar provisions to reasoning. 

For example, it is possible to prove that foldr mappend mempty (x:xs) =
foldr1 mappend (x:xs).  Which means that anywhere in the source where we see
the former, we can clean it up to the latter.  However, if monad laws
don't apply to partial values, then we first have to prove that none of the
(x:xs) are _|_, perhaps even that no substrings are _|_.  This is a much
more involved transformation, so much so that you probably just wouldn't do
it if you want to be correct.

Bottoms are part of Haskell's semantics; theorems and laws have to apply to
them to.  You can pretend they don't exist, but then you have to be okay
with never using an infinite data structure.  I.e. if your programs would
run just as well in Haskell as they would in a call-by-value language, then
you don't have to worry about bottoms.

Luke




--
Russell O'Connor  http://r6.ca/
``All talk about `theft,''' the general counsel of the American Graphophone
Company wrote, ``is the merest claptrap, for there exists no property in
ideas musical, literary or artistic, except as defined by statute.''___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Generalizing a filter-making function

2009-01-23 Thread Dominic Espinosa
Thanks, that does help. I see I was unnecessarily passing a function
parameter (as a newcomer to Haskell, I tend to forget how to properly
use composition). 

The reason to do these maneuvers is that the particular accessor
function to use is being parsed from user input. The main problem is
along the lines of: given a user input string such as s  5, t 'baz',
return a list of all Foos f such that (s f  5) and ('baz' `elem` $ t f). 

Someone else tipped me off about Parsec's expression parsing support, so
I need to look at that as well. The expressions to be parsed are very
minimal, however, so I'm not sure it's entirely necessary.

Thanks again.

On Fri, Jan 23, 2009 at 05:39:07PM -0500, Ross Mellgren wrote:
 makeFilter :: (b - b - Bool) - (a - b) - b - a - Bool
 makeFilter (==) proj expected = (expected ==) . proj
 
 makeEqFilter :: Eq b = (a - b) - b - a - Bool
 makeEqFilter = makeFilter (==)
 
 Then you have a foo:
 
 data Foo = Foo { fooA :: String, fooB :: Int }
 
 foos = [Foo a 1, Foo b 2]
 
 filter (makeEqFilter fooA 1) foos
 
 and so on.
 
 Though this is not really buying you all that much over
 
 filter ((1 ==) . fooA) foos
 
 Or for storing
 
 data Query a = Query String (a - Bool)
 
 let myQuery = Query Test if fst is 1 ((1 ==) . fst)
 
 ...
 
 filter myQuery foos
 
 Does this help?
 
 -Ross
 
 On Jan 23, 2009, at 4:20 PM, Dominic Espinosa wrote:
 
 Novice question here. Sorry if the post is wordy.
 
 In the following code (which doesn't actually compile as-is), I'm  
 trying
 to generalize these 'make*Filter' functions into a single 'makeFilter'
 function. However, I can't get the types to work right.
 
 Foo is a tuple type on which a large number of accessor functions are
 defined. All of them have type Foo - Int, Foo - String, or Foo
 - [a] (so far).
 
 I tried defining 'Query' using exsistential types instead, but had
 difficulty with 'escaped type variables' when I tried to write a
 generalized 'makeFilter' function.
 
 The general point of makeFilter is to take as parameters a Query, a
 value, a comparison function, and then return a function (Foo -  
 Bool).
 This returned function takes as its argument an object of type Foo,
 applies the function 'q' to it, compares that value to 'val', and
 finally returns a Bool.
 
 Later on in the program, a list of these filter functions is to be  
 used
 with a list of Foo objects, to determine which Foo objects satisfy all
 of the filters.
 
 Advice would be greatly appreciated.
 
 --- code ---
 
 data Query a = Query { query_identifier :: String, query_func ::  
 (Foo - a) }
 
 makeIntFilter :: Query Int - Int - (Int - Int - Bool)
 - (Foo - Bool)
 makeIntFilter q val cmp = (\k - val `cmp` (query_func q $ k))
 
 makeStringFilter :: Query String - String - (String - String -  
 Bool)
- (Foo - Bool)
 makeStringFilter q val cmp =  (\k - val `cmp` (query_func q $ k))
 
 -- ??? broken, and the 'cmp' argument is thrown away, which seems  
 wrong
 makeMemberFilter :: Eq a = Query [a] - a - (a - a - a)
- (Foo - Bool)
 makeMemberFilter q val cmp =(\k - val `elem` (query_func q $ k))
 
 ___
 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] how to implement daemon start and stop directives?

2009-01-23 Thread Brandon S. Allbery KF8NH

On 2009 Jan 22, at 1:36, Belka wrote:
Could somebody please share some experience on how to implement  
daemon start

and stop directives. In theory I need something like this:
1. my_daemon start - starts my app with an infinite loop of serving
inside.
2. my_daemon stop - puts in some TVar a value signalizing, that  
stop is

given - infinite loop brakes.
3. ...it on Linux platform.

Thanks in advance!


If you want a normal daemon, you want to look at System.Posix.Process  
to create a proper daemon (forkProcess, createSession; don't forget to  
close stdOutput (and, errr, Haskell library types:  stdin and stderr  
are where?  not System.Posix.IO with stdOutput) and reopen them on / 
dev/null, at least if they're ttys as determined by  
System.Posix.Terminal.queryTerminal).  You also want to write out a  
pidfile (/var/run/programname.pid) for use by startproc / killproc,  
and you want to install a handler for sigTERM  
(System.Posix.Signals.installHandler) which sets the exit flag (TVar,  
MVar, IORef, Chan, take your pick).  Ideally you also catch sigHUP and  
reload your state.


--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
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] how to implement daemon start and stop directives?

2009-01-23 Thread Brandon S. Allbery KF8NH

On 2009 Jan 22, at 3:11, Belka wrote:
Actually, I'm more interested in technical details how to  
communicate from

shell with background process - how to send commands to it. Currently
looking into POSIX libraries hope to find answers there...
Also, maybe a FIFO-pipe-file would solve my problem. Imagine writing a
command in it, while one of daemon's thread is locked-while-awaits for
anything to come out from the other side of the pipe...


You can try it; make sure to open the FIFO for read+write to avoid  
deadlocks, and I think there are some weird behaviors caused by the  
GHC runtime's non-blocking IO.  It will be a lot easier to use a  
socket (AF_INET or AF_UNIX depending on whether you want to support  
remote access or not).


--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
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] Generalizing a filter-making function

2009-01-23 Thread Ross Mellgren
Parsec is an awesome piece of software. Throw away anything you might  
know from writing parsers in something else -- writing parsers with  
parsec is so succinct you can use it most anytime without feeling like  
you're resorting to it.


-Ross

On Jan 23, 2009, at 11:26 PM, Dominic Espinosa wrote:


Thanks, that does help. I see I was unnecessarily passing a function
parameter (as a newcomer to Haskell, I tend to forget how to properly
use composition).

The reason to do these maneuvers is that the particular accessor
function to use is being parsed from user input. The main problem is
along the lines of: given a user input string such as s  5, t  
'baz',
return a list of all Foos f such that (s f  5) and ('baz' `elem` $  
t f).


Someone else tipped me off about Parsec's expression parsing  
support, so

I need to look at that as well. The expressions to be parsed are very
minimal, however, so I'm not sure it's entirely necessary.

Thanks again.

On Fri, Jan 23, 2009 at 05:39:07PM -0500, Ross Mellgren wrote:

makeFilter :: (b - b - Bool) - (a - b) - b - a - Bool
makeFilter (==) proj expected = (expected ==) . proj

makeEqFilter :: Eq b = (a - b) - b - a - Bool
makeEqFilter = makeFilter (==)

Then you have a foo:

data Foo = Foo { fooA :: String, fooB :: Int }

foos = [Foo a 1, Foo b 2]

filter (makeEqFilter fooA 1) foos

and so on.

Though this is not really buying you all that much over

filter ((1 ==) . fooA) foos

Or for storing

data Query a = Query String (a - Bool)

let myQuery = Query Test if fst is 1 ((1 ==) . fst)

...

filter myQuery foos

Does this help?

-Ross

On Jan 23, 2009, at 4:20 PM, Dominic Espinosa wrote:


Novice question here. Sorry if the post is wordy.

In the following code (which doesn't actually compile as-is), I'm
trying
to generalize these 'make*Filter' functions into a single  
'makeFilter'

function. However, I can't get the types to work right.

Foo is a tuple type on which a large number of accessor functions  
are

defined. All of them have type Foo - Int, Foo - String, or Foo
- [a] (so far).

I tried defining 'Query' using exsistential types instead, but had
difficulty with 'escaped type variables' when I tried to write a
generalized 'makeFilter' function.

The general point of makeFilter is to take as parameters a Query, a
value, a comparison function, and then return a function (Foo -
Bool).
This returned function takes as its argument an object of type Foo,
applies the function 'q' to it, compares that value to 'val', and
finally returns a Bool.

Later on in the program, a list of these filter functions is to be
used
with a list of Foo objects, to determine which Foo objects satisfy  
all

of the filters.

Advice would be greatly appreciated.

--- code ---

data Query a = Query { query_identifier :: String, query_func ::
(Foo - a) }

makeIntFilter :: Query Int - Int - (Int - Int - Bool)
  - (Foo - Bool)
makeIntFilter q val cmp = (\k - val `cmp` (query_func q $ k))

makeStringFilter :: Query String - String - (String - String -
Bool)
 - (Foo - Bool)
makeStringFilter q val cmp =  (\k - val `cmp` (query_func q $ k))

-- ??? broken, and the 'cmp' argument is thrown away, which seems  
wrong

makeMemberFilter :: Eq a = Query [a] - a - (a - a - a)
 - (Foo - Bool)
makeMemberFilter q val cmp =(\k - val `elem` (query_func q $ k))

___
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] How to define an operation in terms of itself (but of different type)?

2009-01-23 Thread Brandon S. Allbery KF8NH

On 2009 Jan 23, at 17:58, Olex P wrote:

class Vector v where
(^+^)   :: v - v - v

class Matrix m where
(^+^) :: m - m - m


You can't reuse the same operator in different classes.  Vector  
owns (^+^), so Matrix can't use it itself.  You could say


 instance Matrix m = Vector m where
   (^+^) = ...

allowing Matrix to inherit Vector's operator (or turn it around the  
other way, make it Matrix then make Vector a Matrix), but that's only  
linguistically possible, not necessarily mathematically sane.


--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
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] How to define an operation in terms of itself (but of different type)?

2009-01-23 Thread Luke Palmer
2009/1/23 Brandon S. Allbery KF8NH allb...@ece.cmu.edu

 On 2009 Jan 23, at 17:58, Olex P wrote:

 class Vector v where
 (^+^)   :: v - v - v

 class Matrix m where
 (^+^) :: m - m - m


 You can't reuse the same operator in different classes.  Vector owns
 (^+^), so Matrix can't use it itself.  You could say

  instance Matrix m = Vector m where
(^+^) = ...


No you can't!  Stop thinking you can do that!

It would be sane to do:

class Vector m = Matrix m where
-- matrix ops that don't make sense on vector

Thus anything that implements Matrix must first implement Vector.  Which is
sane because matrices are square vectors with some additional structure, in
some sense.

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


Re: Laws and partial values (was: [Haskell-cafe] mapM_ - Monoid.Monad.map)

2009-01-23 Thread Thomas Davie


On 24 Jan 2009, at 02:33, Luke Palmer wrote:


On Fri, Jan 23, 2009 at 6:10 PM, rocon...@theorem.ca wrote:
On Fri, 23 Jan 2009, Derek Elkins wrote:

mempty `mappend` undefined = undefined (left identity monoid law)
The above definition doesn't meet this, similarly for the right  
identity
monoid law.  That only leaves one definition, () `mappend` () = ()  
which

does indeed satisfy the monoid laws.

So the answer to the question is Yes.  Another example of making
things as lazy as possible going astray.

I'd like to argue that laws, such as monoid laws, do not apply to  
partial values.  But I haven't thought my position through yet.


Please try to change your mind.


I'd actually argue that this is just the wrong way of formulating my  
statement.  Please correct my possibly ill informed maths, if Im doin  
it rong though...


Isn't the point of bottom that it's the least defined value.  Someone  
above made the assertion that for left identity to hold, _|_ `mappend`  
() must be _|_.  But, as there is only one value in the Unit type, all  
values we have no information about must surely be that value, so this  
is akin to saying () `mappend` () must be (), which our definition  
gives us.


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