Re: [Haskell-cafe] Review request for my encoding function

2011-01-07 Thread Ivan Lazar Miljenovic
On 8 January 2011 16:27, C K Kashyap  wrote:
> Hi,
> I've written a function to encode a color value of type (Int,Int,Int)
> into 8,16 or 32 byte ByteString depending on the value of bits per
> pixel. This is for my VNC server implementation.
> I'd appreciate some feedback on the Haskellism of the implementation.
>
> import Data.Bits
> import Data.ByteString.Lazy
> import Data.Binary.Put
> import Data.Word
>
> type Red = Int
> type Green = Int
> type Blue = Int
> type Color = (Red,Green,Blue)
>
>
>
> encode :: Color -> Int-> Int-> Int-> Int-> Int-> Int-> Int -> ByteString
> encode (r,g,b) bitsPerPixel redMax greenMax blueMax redShift
> greenShift blueShift = runPut $ do
>        case bitsPerPixel of
>                8       -> putWord8 z8
>                16      -> putWord16be z16
>                32      -> putWord32be z32
>        where
>                z8  = (fromIntegral $ nr + ng + nb) :: Word8
>                z16 = (fromIntegral $ nr + ng + nb) :: Word16
>                z32 = (fromIntegral $ nr + ng + nb) :: Word32
>                nr = scale r redMax redShift
>                ng = scale g greenMax greenShift
>                nb = scale b blueMax blueShift
>                scale c cm cs = (c * cm `div` 255) `shift` cs

The more "Haskellian" approach would be to use a dedicated datatype to
specify the number of bits, not to have a partial function on Int.
Possibly even encode the RGB triple such that it specifies the number
of bits rather than separating each value.

-- 
Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com
IvanMiljenovic.wordpress.com

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


[Haskell-cafe] Review request for my encoding function

2011-01-07 Thread C K Kashyap
Hi,
I've written a function to encode a color value of type (Int,Int,Int)
into 8,16 or 32 byte ByteString depending on the value of bits per
pixel. This is for my VNC server implementation.
I'd appreciate some feedback on the Haskellism of the implementation.

import Data.Bits
import Data.ByteString.Lazy
import Data.Binary.Put
import Data.Word

type Red = Int
type Green = Int
type Blue = Int
type Color = (Red,Green,Blue)



encode :: Color -> Int-> Int-> Int-> Int-> Int-> Int-> Int -> ByteString
encode (r,g,b) bitsPerPixel redMax greenMax blueMax redShift
greenShift blueShift = runPut $ do
case bitsPerPixel of
8   -> putWord8 z8
16  -> putWord16be z16
32  -> putWord32be z32
where
z8  = (fromIntegral $ nr + ng + nb) :: Word8
z16 = (fromIntegral $ nr + ng + nb) :: Word16
z32 = (fromIntegral $ nr + ng + nb) :: Word32
nr = scale r redMax redShift
ng = scale g greenMax greenShift
nb = scale b blueMax blueShift
scale c cm cs = (c * cm `div` 255) `shift` cs



Regards,
Kashyap

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


Re: [Haskell-cafe] Type System vs Test Driven Development

2011-01-07 Thread Evan Laforge
> I should say that this reimplementation would be good. If you can
> compare two implementations (one in plain Haskell and second in
> declarative QuickCheck rules) you will be better that with only one.

This presumes I know how to write a simple but slow version.  Clearly,
that's an excellent situation, since you can trust your simple but
slow version more than the complex but fast one.  Unfortunately, I'm
usually hard enough pressed to write just the slow version.  If I
could think of a simpler way to write it I'd be really set, but I'm
already writing things in the simplest possible way I know how.

> Doing two implementation for testing purposes can be boldly likened to
> code review with only one person.

Indeed, but unfortunately it still all comes from the same brain.  So
if it's too low level, I'll make the same wrong assumptions about the
input.  If it's too high level, then writing a whole new program is
too much work.  I think you make a good point, but one that's only
applicable in certain situations.

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


Re: [Haskell-cafe] Is this the "right" way to do polymorphism?

2011-01-07 Thread Luke Palmer
If you always expect to be passing c as a parameter and never
returned, it is probably better off as a data type.  Eg. HTTPClient
might look like a traditional OO class:

class HTTPClient c where
foo :: c -> stuff
bar :: c -> stuff

I've found that it is easier to work with if you use a data type instead:

data HTTPClient = HTTPClient {
foo :: stuff,
bar :: stuff
}

But other than that, yeah that's about right.  If you want a function
to be polymorphic in something, take the something as a parameter.
Simple as that.

Luke

On Fri, Jan 7, 2011 at 8:01 PM, Daryoush Mehrtash  wrote:
> I am trying to evaluate the polymorphism technique used in Hackage library.
> I like to know if the approach taken is "right" or not.
>
> The code in question is in the Hoaut package
> http://hackage.haskell.org/package/hoauth/
>
> As far as I can understand the code wants to have polymorphism on HTTP
> client such that it can use different underlying HTTP.  The package comes
> with Curl and Debug implementation of its HTTPClient class.
>
> My question is with how the polymorphism is used.  In function such as
> "serviceRequest" in the Network.OAuth.Consumer module you have:
>
>
> -- | Performs a signed request with the available token.
> serviceRequest :: (HttpClient c,MonadIO m) => c -> OAuthRequest ->
> OAuthMonadT m Response
>
> serviceRequest c req = do { result <- lift $ runClient c (unpackRq req)
>
>   ; case (result)
>
> of Right rsp -> return rsp
>
>Left err  -> fail $ "Failure performing the
> request. [reason=" ++ err ++"]"
>
>   }
>
>
>
> The function expects the HTTPClient implementation to be the first argument
> to the function.  Is that the right thing to do?   Or should
> the instance of the client be a type parameter in the computation (in this
> case OAuthMonadT)?
>
> thanks,
>
> Daryoush
>
> ___
> 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] Generalizing catMaybes

2011-01-07 Thread David Menendez
On Fri, Jan 7, 2011 at 9:56 PM, Tony Morris  wrote:
>
>  I am wondering if it possible to generalise catMaybes:
>
> (Something f, SomethingElse t) => t (f a) -> t a
>
> I have being doing some gymnastics with Traversable and Foldable and a
> couple of other things from category-extras to no avail. Perhaps
> someone else's brain is molded into an appropriate shape to reveal an
> answer!


This gets you part of the way there:

(>>= maybe mzero return) :: (MonadPlus m) => m (Maybe a) -> m a

I'm not sure what the SomethingElse should look like. One possibility
would be Foldable.

(>>= Data.Foldable.foldr (mplus . return) mzero)
  :: (MonadPlus m, Foldable t) => m (t a) -> m a



I have a MonadPlus-to-Monoid wrapper I call MSum, so I could also write it,

(>>= getMSum . foldMap (MSum . return))
  :: (MonadPlus m, Foldable t) => m (t a) -> m a


-- 
Dave Menendez 


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


Re: [Haskell-cafe] Type System vs Test Driven Development

2011-01-07 Thread Evan Laforge
On Wed, Jan 5, 2011 at 7:31 PM, Chung-chieh Shan
 wrote:
> Besides those example inputs and expected outputs, what about:
> If two signals are (in)compatible then after applying some simple
> transformations to both they remain (in)compatible?  A certain family of
> signals is always compatible with another family of signals?  Silence is
> compatible with every signal?  Every non-silent signal is (in)compatible
> with itself (perhaps after applying a transformation)?

Well, signals are never transformed.  Silence is, in fact, not
specially compatible.  The most I can say is that signals that don't
overlap are always compatible.  So you're correct in that it's
possible to extract properties.  However, this particular property,
being simple, is also expressed in a simple way directly in the code,
so past a couple tests to make sure I didn't reverse any (>)s, I don't
feel like it needs the exhaustive testing that quickcheck brings to
bear.  And basically it's just reimplementing a part of the original
function, in this case the first guard... I suppose you could say if I
typoed the (>)s in the original definition, maybe I won't in the test
version.  But this is too low level, what I care about is if the whole
thing has the conceptually simple but computationally complex result
that I expect.  The interesting bug is when the first guard shadows an
exception later on, so it turns out it's *not* totally true that
non-overlapping signals must be compatible, or maybe my definition of
"overlapping" is not sufficiently defined, or defined different ways
in different places, or needs to be adjusted, or  I suppose input
fuzzing should be able to flush out things like fuzzy definitions of
overlapping

I can also say weak things about complex outputs, that they will be
returned in sorted order, that they won't overlap, etc.  But I those
are rarely the interesting complicated things that I really want to
test.  Even my "signal compatibility" example is relatively amenable
to extracting properties, picking some other examples:

- Having a certain kind of syntax error will result in a certain kind
of error msg, and surrounding expressions will continue to be included
in the output.  The error msg will include the proper location.  So
I'd need an Arbitrary to generate the right structure with an error or
two and then have code to figure out the reported location from the
location in the data structure, and debug all that.  There's actually
a fair amount of stuff that wants to look for a log msg, like "hit a
cache, the only sign of which is a log msg of a certain format".
Certainly caches can be tested by asserting that you get the same
results with the cache turned off, that's an easy property.

- Hitting a certain key sequence results in certain data being entered
in the UI.  There's nothing particularly "property" like about this,
it's too ad-hoc...  this seems to apply for all UI-level tests.

- There's also a large class of "integration" type tests: I've tested
the signal compatibility function separately, but the final proof is
that the high-level user input of this shape results in this output,
due to do signal compatibility.  These are the ones whose failure is
the most valuable because they test the emergent behaviour of a set of
interacting systems, and that's ultimately the user-visible behaviour
and also the place where the results are the most subtle.  But those
are also the ones that have huge state spaces and, similar to the UI
tests, basically ad-hoc relationships between input and output.

- Testing for laziness of course doesn't work either.  Or timed
things.  As far as performance goes, some can be tested with tests
("taking the first output doesn't force the entire input" or "a new
key cancels the old threads and starts new ones") but some must be
tested with profiling and eyeballing the results.

QuickCheck seems to fit well when you have small input and output
spaces, but complicated stuff in the middle, but still simple
relations between the input and output.  I think that's why data
structures are so easy to QuickCheck.  I suppose I should look around
for more use of QuickCheck for non-data structures... the examples
I've seen have been trivial stuff like 'reverse . reverse = id'.

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


Re: [Haskell-cafe] Generalizing catMaybes

2011-01-07 Thread Brandon S Allbery KF8NH
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 1/7/11 21:56 , Tony Morris wrote:
>  I am wondering if it possible to generalise catMaybes:
> 
> (Something f, SomethingElse t) => t (f a) -> t a
> 
> I have being doing some gymnastics with Traversable and Foldable and a
> couple of other things from category-extras to no avail. Perhaps
> someone else's brain is molded into an appropriate shape to reveal an
> answer!

Looks to me like you want something like:

> mtraverse :: (Traversable t, Monoid m) => t m -> m
> mtraverse xs = traverse mappend (mempty:xs)

or possibly the same kind of thing using MonadPlus instead of Monoid.

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


- -- 
brandon s. allbery [linux,solaris,freebsd,perl]  allb...@kf8nh.com
system administrator  [openafs,heimdal,too many hats]  allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon university  KF8NH
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk0n20AACgkQIn7hlCsL25V0MACeIJjbHmIjnABHxpykeVdcZ62f
fS0AoL2xet/PpuvyuioWNvbzCTqWz5Z/
=2HGT
-END PGP SIGNATURE-

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


[Haskell-cafe] Is this the "right" way to do polymorphism?

2011-01-07 Thread Daryoush Mehrtash
I am trying to evaluate the polymorphism technique used in Hackage library.
I like to know if the approach taken is "right" or not.

The code in question is in the Hoaut package
http://hackage.haskell.org/package/hoauth/

As far as I can understand the code wants to have polymorphism on HTTP
client such that it can use different underlying HTTP.  The package comes
with Curl and Debug implementation of its HTTPClient class.

My question is with how the polymorphism is used.  In function such as
"serviceRequest" in the Network.OAuth.Consumer module you have:


-- | Performs a signed request with the available token.
serviceRequest :: (HttpClient c,MonadIO m) => c -> OAuthRequest ->
OAuthMonadT m Response
serviceRequest c req = do { result <- lift $ runClient c (unpackRq req)
  ; case (result)
of Right rsp -> return rsp
   Left err  -> fail $ "Failure performing
the request. [reason=" ++ err ++"]"
  }



The function expects the HTTPClient implementation to be the first argument
to the function.  Is that the right thing to do?   Or should
the instance of the client be a type parameter in the computation (in this
case OAuthMonadT)?

thanks,

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


[Haskell-cafe] Generalizing catMaybes

2011-01-07 Thread Tony Morris

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

 I am wondering if it possible to generalise catMaybes:

(Something f, SomethingElse t) => t (f a) -> t a

I have being doing some gymnastics with Traversable and Foldable and a
couple of other things from category-extras to no avail. Perhaps
someone else's brain is molded into an appropriate shape to reveal an
answer!

- -- 
Tony Morris
http://tmorris.net/

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk0n0lwACgkQmnpgrYe6r6155gCeLjYizQ/5w1r2qkecbEqiQqq5
ihIAn1bmmK/qNFxM2sSusqjJu/g2/lH7
=+SdM
-END PGP SIGNATURE-


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


Re: [Haskell-cafe] Ur vs Haskell

2011-01-07 Thread Brandon S Allbery KF8NH
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 1/7/11 14:14 , Alexander Kjeldaas wrote:
> Ur looks very impressive, so the natural question I'm asking myself is:  How
> does it stack up against haskell frameworks, and why can't Ur be implemented
> in Haskell?  
> 
> I'm thinking mainly of the safety guarantees, not necessarily the
> performance guarantees, GC-less execution, or even non-lazy evaluation.
> 
> And I can't answer those.. any takers?

Right on the intro page it talks about having simplified dependent typing.
While some (not all) forms of dependent typing can be simulated in Haskell,
"simple" is not the word to describe the techniques.

- -- 
brandon s. allbery [linux,solaris,freebsd,perl]  allb...@kf8nh.com
system administrator  [openafs,heimdal,too many hats]  allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon university  KF8NH
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk0nygQACgkQIn7hlCsL25UUcACfSbSvzrFF3hFtPIOeV6+SEkCF
0dUAn3V4ozEYg/U6rzOYysaJXM7xKzBQ
=QUia
-END PGP SIGNATURE-

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


Re: [Haskell-cafe] Building lambdabot

2011-01-07 Thread Brandon S Allbery KF8NH
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 1/6/11 02:27 , Joe Bruce wrote:
> Now I'm stuck on readline again [lambdabot build step 28 of 81]:
> "/Users/joe/.cabal/lib/readline-1.0.1.0/ghc-6.12.3/HSreadline-1.0.1.0.o:
> unknown symbol `_rl_basic_quote_characters'"

This sounds like the cabal readline package (the Haskell bindings) used
Apple's libreadline (which is really libedit, so doesn't have most readline
functionality).  I'd forcibly reinstall readline-1.0.1.0 and then try again.

- -- 
brandon s. allbery [linux,solaris,freebsd,perl]  allb...@kf8nh.com
system administrator  [openafs,heimdal,too many hats]  allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon university  KF8NH
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk0nvyYACgkQIn7hlCsL25X1kQCgpnQIC4GmI0fUBh5E+3Z9vXBx
T8MAn35u+cna0Dni+amapHXFsukpb8wz
=fnWv
-END PGP SIGNATURE-

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


Re: [Haskell-cafe] Building lambdabot

2011-01-07 Thread Joe Bruce
On Fri, Jan 7, 2011 at 8:00 AM, Max Bolingbroke
wrote:
>
> I don't think readline links against iconv. What that error says to me
> is that GHC is failing to link against *any* iconv. I bet that it's
> because you have iconv installed via Macports without +universal. Try:
>
> $ file /opt/local/lib/libiconv.a
>
> It should say:
>
> /opt/local/lib/libiconv.a: Mach-O universal binary with 2 architectures
> /opt/local/lib/libiconv.a (for architecture i386):  current ar archive
> random library
> /opt/local/lib/libiconv.a (for architecture x86_64):current ar
> archive random library
>
>
If nothing else, I've learned about checking locations and architectures of
libraries in this little adventure, so I had checked that prior to writing.
 I do in fact have the universal binary installed.  What's more, both the
macport and system versions are universal.  I tried telling cabal to
explicitly use each, separately, and it failed both times, though it gave me
a different error when compiling against the system lib.  (It complained
about readline again, which is why I assumed readline had some dependency on
iconv.)

I'm going to try what Gwern recommended (using the darcs repository for
lambdabot) before I continue down this route.

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


Re: [Haskell-cafe] Freeglut

2011-01-07 Thread Brandon S Allbery KF8NH
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 1/3/11 18:21 , Eric wrote:
> I would like to use freeglut instead of GLUT for my Haskell OpenGL program,
> but when I place the freeglut dll in the program's directory and try to run
> the program on Windows XP, I get the following error message:
> 
> user error (unknown GLUT call glutSetOption, check for freeglut)

That would mean that it's known that freeglut doesn't have some necessary
functions, and it's telling you to use a real GLUT.

- -- 
brandon s. allbery [linux,solaris,freebsd,perl]  allb...@kf8nh.com
system administrator  [openafs,heimdal,too many hats]  allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon university  KF8NH
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk0ntVYACgkQIn7hlCsL25UiIgCgxwaNeCh1JMiqJsFxdEpnq6kK
3AEAoJYhqNjuQrAaKF39NrFuFy/OG0UP
=7RQ8
-END PGP SIGNATURE-

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


Re: [Haskell-cafe] Newbie type question for wxHaskell learner

2011-01-07 Thread b1g3ar5
Yes you're right I had brackets wrong (and the 'where' version is
easier to read), thanks.

I think the where style works best - or maybe flip and a dangling \x-
>.

I maybe slow but I'm learning.

N


On Jan 7, 7:21 pm, Daniel Fischer 
wrote:
> On Friday 07 January 2011 19:45:26, b1g3ar5 wrote:
>
> > Nearly - the first suggestion doesn't work because each es needs a new
> > panel I can't use the same one each time.
>
> > The second suggestion doesn't quite work because the x in [text :=
> > contents x] is not in scope of the \p function.
>
> Hmm,
>
> Prelude Graphics.UI.WX> :t \w ->  mapM (\x -> panel w [] >>= \p -> textCtrl
> p [text := x])
> \w ->  mapM (\x -> panel w [] >>= \p -> textCtrl p [text := x])
>   :: Window a -> [String] -> IO [TextCtrl ()]
>
> x is in scope as far as I can tell, the mapM'd lambda is
>
> mapM (\x -> (panel nb [] >>= \p -> textCtrl p [text := contents x]))
> my_list
>
> or
>
> mapM foo my_list
>    where
>       foo x = do
>                 p <- panel nb []
>                 textCtrl p [text := contents x]
>
> x is bound in a scope enclosing p's scope, so it is (or should be)
> available.
>
> What does the compiler say exactly?
>
> ___
> Haskell-Cafe mailing list
> haskell-c...@haskell.orghttp://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] Type System vs Test Driven Development

2011-01-07 Thread Florian Weimer
* Jonathan Geddes:

> When I write Haskell code, I write functions (and monadic actions)
> that are either a) so trivial that writing any kind of unit/property
> test seems silly, or are b) composed of other trivial functions using
> equally-trivial combinators.

You can write in this style in any language which has good support for
functional composition (which means some sort of garbage collection
and perhaps closures, but strong support for higher-order functions is
probably not so important).  But this doesn't mean that you don't have
bugs.  There are a few error patterns I've seen when following this
style (albeit not in Haskell):

While traversing a data structure (or parsing some input), you fail to
make progress and end up in an infinite loop.

You confuse right and left (or swap two parameters of the same type),
leading to wrong results.

All the usual stuff about border conditions still applies.

Input and output is more often untyped than typed.  Typos in magic
string constants (such as SQL statements) happen frequently.

Therefore, I think that you cannot really avoid extensive testing for
a large class of programming tasks.

> I vehemently disagreed, stating that invariants embedded in the type
> system are stronger than any other form of assuring correctness I know
> of.

But there are very interesting invariants you cannot easily express in
the type system, such as "this list is of finite length".  It also
seems to me that most Haskell programmers do not bother to turn the
typechecker into some sort of proof checker.  (Just pick a few
standard data structures on hackage and see if they perform such
encoding. 8-)

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


Re: [Haskell-cafe] Newbie type question for wxHaskell learner

2011-01-07 Thread Daniel Fischer
On Friday 07 January 2011 19:45:26, b1g3ar5 wrote:
> Nearly - the first suggestion doesn't work because each es needs a new
> panel I can't use the same one each time.
>
> The second suggestion doesn't quite work because the x in [text :=
> contents x] is not in scope of the \p function.

Hmm,

Prelude Graphics.UI.WX> :t \w ->  mapM (\x -> panel w [] >>= \p -> textCtrl 
p [text := x])
\w ->  mapM (\x -> panel w [] >>= \p -> textCtrl p [text := x])
  :: Window a -> [String] -> IO [TextCtrl ()]

x is in scope as far as I can tell, the mapM'd lambda is

mapM (\x -> (panel nb [] >>= \p -> textCtrl p [text := contents x])) 
my_list

or

mapM foo my_list
   where
  foo x = do
p <- panel nb []
textCtrl p [text := contents x]

x is bound in a scope enclosing p's scope, so it is (or should be) 
available.

What does the compiler say exactly?


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


[Haskell-cafe] Ur vs Haskell

2011-01-07 Thread Alexander Kjeldaas
I've briefly gone through the Ur demo at http://impredicative.com/ur/demo/

Ur looks very impressive, so the natural question I'm asking myself is:  How
does it stack up against haskell frameworks, and why can't Ur be implemented
in Haskell?

I'm thinking mainly of the safety guarantees, not necessarily the
performance guarantees, GC-less execution, or even non-lazy evaluation.

And I can't answer those.. any takers?

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


Re: [Haskell-cafe] Newbie type question for wxHaskell learner

2011-01-07 Thread b1g3ar5
Nearly - the first suggestion doesn't work because each es needs a new
panel I can't use the same one each time.

The second suggestion doesn't quite work because the x in [text :=
contents x] is not in scope of the \p function.

Thanks.

N


On Jan 7, 6:29 pm, Daniel Fischer 
wrote:
> On Friday 07 January 2011 19:01:43, b1g3ar5 wrote:
>
>
>
>
>
>
>
>
>
> > Thanks for your reply but it doesn't quite solve the problem. This:
>
> > plist <- mapM (\x-> (panel nb [])) my_list
>
> > returns [Panel()] and works as you say, but:
>
> > elist <- mapM (\x-> (textCtrl (panel nb []) [text := contents x]))
> > my_list
>
> > still won't work because the function panel returns a IO (Panel()) and
> > so won't do as a parameter to textCtrl.
>
> > I can get round this by applying mapM to a list of the indices (of
> > my_list and plist:
>
> > elist <- mapM (\ix-> (textCtrl (plist!!ix) [text := contents (my_list!!
> > ix)])) [1..4]
>
> > but this seems a bit crap. There must be a neat way of doing this.
>
> Depends on the semantics of panel, maybe
>
> do whatever
>    p <- panel nb []
>    es <- mapM (\x -> textCtrl p [text := contents x]) my_list
>    moreWith es
>
> does what you want. If panel has side effects you need for every item in
> the list,
>
> do whatever
>    es <- mapM (\x -> panel nb [] >>=
>                      \p -> textCtrl p [text:=contents x]) my_list
>    moreWith es
>
> ought to do it.
>
> ___
> Haskell-Cafe mailing list
> haskell-c...@haskell.orghttp://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] Newbie type question for wxHaskell learner

2011-01-07 Thread Daniel Fischer
On Friday 07 January 2011 19:01:43, b1g3ar5 wrote:
> Thanks for your reply but it doesn't quite solve the problem. This:
>
> plist <- mapM (\x-> (panel nb [])) my_list
>
> returns [Panel()] and works as you say, but:
>
> elist <- mapM (\x-> (textCtrl (panel nb []) [text := contents x]))
> my_list
>
> still won't work because the function panel returns a IO (Panel()) and
> so won't do as a parameter to textCtrl.
>
> I can get round this by applying mapM to a list of the indices (of
> my_list and plist:
>
> elist <- mapM (\ix-> (textCtrl (plist!!ix) [text := contents (my_list!!
> ix)])) [1..4]
>
> but this seems a bit crap. There must be a neat way of doing this.

Depends on the semantics of panel, maybe

do whatever
   p <- panel nb []
   es <- mapM (\x -> textCtrl p [text := contents x]) my_list
   moreWith es

does what you want. If panel has side effects you need for every item in 
the list,

do whatever
   es <- mapM (\x -> panel nb [] >>= 
 \p -> textCtrl p [text:=contents x]) my_list
   moreWith es

ought to do it.

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


Re: [Haskell-cafe] Newbie type question for wxHaskell learner

2011-01-07 Thread b1g3ar5
Thanks for your reply but it doesn't quite solve the problem. This:

plist <- mapM (\x-> (panel nb [])) my_list

returns [Panel()] and works as you say, but:

elist <- mapM (\x-> (textCtrl (panel nb []) [text := contents x]))
my_list

still won't work because the function panel returns a IO (Panel()) and
so won't do as a parameter to textCtrl.

I can get round this by applying mapM to a list of the indices (of
my_list and plist:

elist <- mapM (\ix-> (textCtrl (plist!!ix) [text := contents (my_list!!
ix)])) [1..4]

but this seems a bit crap. There must be a neat way of doing this.

N


On Jan 7, 4:21 pm, Daniel Fischer 
wrote:
> On Friday 07 January 2011 17:09:11, b1g3ar5 wrote:
>
> > I've tried to solve this but I am failing.
>
> > I can do this:
>
> > p0<-panel nb []
> > e0<-textCtrl p [text:=my_list!!0]
>
> > but I want to do this on all of my_list, so I tried:
>
> > let es = map (\x-> textCtrl (panel nb []) [text:=x]) my_list
>
> > Now, this won't work because the panel nb [] is IO (Panel()) and the
> > parameter to textCtrl needs to be a Panel()
>
> > How do I get out of IO?
>
> What you need is mapM:
>
>     es <- mapM (\x -> textCtrl (panel nb []) [text:=x]) my_list
>
> mapM :: (Monad m) => (a -> m b) -> [a] -> m [b]
>
> applies the function to each list element, runs the resulting action and
> collects the results. If you don't need the results but only the effects of
> running the actions (common in IO), use
>
> mapM_ :: (Monad m) => (a -> m b) -> [a] -> m ()
>
> mapM and mapM_ are compositions of
>
> sequence :: (Monad m) => [m a] -> m [a]
>
> resp.
>
> sequence_ :: (Monad m) => [m a] -> m ()
>
> with map (mapM f list === sequence (map f list)), those are useful on their
> own too.
>
>
>
> > Thanks.
>
> ___
> Haskell-Cafe mailing list
> haskell-c...@haskell.orghttp://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] Newbie type question for wxHaskell learner

2011-01-07 Thread Daniel Fischer
On Friday 07 January 2011 17:09:11, b1g3ar5 wrote:
> I've tried to solve this but I am failing.
>
> I can do this:
>
> p0<-panel nb []
> e0<-textCtrl p [text:=my_list!!0]
>
> but I want to do this on all of my_list, so I tried:
>
> let es = map (\x-> textCtrl (panel nb []) [text:=x]) my_list
>
> Now, this won't work because the panel nb [] is IO (Panel()) and the
> parameter to textCtrl needs to be a Panel()
>
> How do I get out of IO?

What you need is mapM:

es <- mapM (\x -> textCtrl (panel nb []) [text:=x]) my_list

mapM :: (Monad m) => (a -> m b) -> [a] -> m [b]

applies the function to each list element, runs the resulting action and 
collects the results. If you don't need the results but only the effects of 
running the actions (common in IO), use

mapM_ :: (Monad m) => (a -> m b) -> [a] -> m ()

mapM and mapM_ are compositions of

sequence :: (Monad m) => [m a] -> m [a]

resp.

sequence_ :: (Monad m) => [m a] -> m ()

with map (mapM f list === sequence (map f list)), those are useful on their 
own too.

>
> Thanks.

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


Re: [Haskell-cafe] Building lambdabot

2011-01-07 Thread Gwern Branwen
On Fri, Jan 7, 2011 at 11:00 AM, Max Bolingbroke
 wrote:
>
> Well, I tried to see if I could reproduce your problem but didn't get
> to this stage. It looks like v4.2.2.1 from Hackage hasn't been updated
> for donkeys years and breaks massively because of at least the new
> exceptions library, mtl 2.0 and the syb package being split off from
> base.

I haven't commented before because most of the issues seemed to be Mac
specific, which I know nothing about, but avoid the Hackage packages
for lambdabot. You should be working out of darcs for lambdabot and
its split-out packages like show or unlambda:
http://code.haskell.org/lambdabot/

Darcs lambdabot ought to work reasonably well with GHC 6.12.1, which
is what I have.

-- 
gwern
http://www.gwern.net

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


Re: [Haskell-cafe] Building lambdabot

2011-01-07 Thread Max Bolingbroke
On 7 January 2011 06:20, Joe Bruce  wrote:
> Thanks Max.  That makes a lot of sense.  That change got me to the point of
> linking lambdabot.

Well, I tried to see if I could reproduce your problem but didn't get
to this stage. It looks like v4.2.2.1 from Hackage hasn't been updated
for donkeys years and breaks massively because of at least the new
exceptions library, mtl 2.0 and the syb package being split off from
base.

I started to fix these issues but lost the will to live at step "[39
of 81] Compiling Plugin.Eval". Do you have access to some fixed source
code that I might be able to build on GHC 7?

> readline is compiled with iconv from
> MacPorts,

I don't think readline links against iconv. What that error says to me
is that GHC is failing to link against *any* iconv. I bet that it's
because you have iconv installed via Macports without +universal. Try:

$ file /opt/local/lib/libiconv.a

It should say:

/opt/local/lib/libiconv.a: Mach-O universal binary with 2 architectures
/opt/local/lib/libiconv.a (for architecture i386):  current ar archive
random library
/opt/local/lib/libiconv.a (for architecture x86_64):current ar
archive random library

If it doesn't, do:

$ sudo port install libiconv +universal

And then link Lambdabot again.

Does that help?
Max

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


[Haskell-cafe] Newbie type question for wxHaskell learner

2011-01-07 Thread b1g3ar5
I've tried to solve this but I am failing.

I can do this:

p0<-panel nb []
e0<-textCtrl p [text:=my_list!!0]

but I want to do this on all of my_list, so I tried:

let es = map (\x-> textCtrl (panel nb []) [text:=x]) my_list

Now, this won't work because the panel nb [] is IO (Panel()) and the
parameter to textCtrl needs to be a Panel()

How do I get out of IO?

Thanks.

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


Re: [Haskell-cafe] HDBC, postgresql, bytestrings and embedded NULLs

2011-01-07 Thread John Goerzen

On 01/07/2011 09:49 AM, John Goerzen wrote:

On 01/07/2011 05:24 AM, Michael Snoyman wrote:

On Fri, Jan 7, 2011 at 11:44 AM, Iustin Pop wrote:
Yes, I had a bug reported in persistent-postgresql that I traced back
to this bug. I reported the bug, but never heard a response. Frankly,
if I had time, I would write a low-level PostgreSQL binding so I could
skip HDBC entirely.


I'm not seeing an open issue at
https://github.com/jgoerzen/hdbc-postgresql/issues -- did you report it
somewhere else?


Along the same lines, I am a volunteer and patches are accepted even 
more happily than bug reports.  It's disheartening to see someone's 
volunteer work reduced to "Bah, it doesn't escape NULLs, so it sucks so 
much that I'll just go write my own."  It would seem to me that 
contributing your skill to fixing issues with existing software would be 
a better thing than having to invent yet another database system.


-- John

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


Re: [Haskell-cafe] HDBC, postgresql, bytestrings and embedded NULLs

2011-01-07 Thread Iustin Pop
On Fri, Jan 07, 2011 at 09:49:35AM -0600, John Goerzen wrote:
> On 01/07/2011 05:24 AM, Michael Snoyman wrote:
> >On Fri, Jan 7, 2011 at 11:44 AM, Iustin Pop  wrote:
> >Yes, I had a bug reported in persistent-postgresql that I traced back
> >to this bug. I reported the bug, but never heard a response. Frankly,
> >if I had time, I would write a low-level PostgreSQL binding so I could
> >skip HDBC entirely.
> 
> I'm not seeing an open issue at
> https://github.com/jgoerzen/hdbc-postgresql/issues -- did you report
> it somewhere else?

Ah, I didn't know it's hosted there. I'm going to fill my report,
thanks!

iustin

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


Re: [Haskell-cafe] HDBC, postgresql, bytestrings and embedded NULLs

2011-01-07 Thread John Goerzen

On 01/07/2011 05:24 AM, Michael Snoyman wrote:

On Fri, Jan 7, 2011 at 11:44 AM, Iustin Pop  wrote:
Yes, I had a bug reported in persistent-postgresql that I traced back
to this bug. I reported the bug, but never heard a response. Frankly,
if I had time, I would write a low-level PostgreSQL binding so I could
skip HDBC entirely.


I'm not seeing an open issue at 
https://github.com/jgoerzen/hdbc-postgresql/issues -- did you report it 
somewhere else?


What would you gain by skipping HDBC?  If there's a problem in the API, 
I'd like to fix it.


-- John

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


Re: [Haskell-cafe] Type System vs Test Driven Development

2011-01-07 Thread Felipe Almeida Lessa
Seeing all the good discussion on this thread, I think we are missing
a TDD page on our Haskell.org wiki.  =)

Cheers,

-- 
Felipe.

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


Re: [Haskell-cafe] Exportable and importable instances

2011-01-07 Thread Gábor Lehel
The objection to this I recall hearing is that it would make it
possible for different parts of the program to see different instances
for a given type (local instances, effectively), which would have
"interesting" results. I don't know if there's a way to implement the
feature which avoids this, or whether also adding support for local
instances is actually part of the plan. (If I'm thinking this through
correctly, this is currently avoided because instances are always
exported, and Main imports all modules transitively, so any
conflicting instances will be visible in Main at the latest.)

On Fri, Jan 7, 2011 at 2:07 PM, Marco Túlio Gontijo e Silva
 wrote:
> Hi.
>
> I'm planning to propose a language extension for Haskell to make it possible 
> to
> control the visibility of type class instances in module export and import
> lists as a research project.  I'm planning to implement this in GHC.  I've
> already mentioned it in #...@irc.freenode.net and got interesting comments 
> from
> tibbe and quicksilver.
>
> I'd be glad to receive more feedback on the idea.  If you have any
> comments, please reply to this thread or mail me individually, at your will.
>
> Greetings.
> --
> marcot
> http://marcot.eti.br/
> [Flattr=54498]
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>



-- 
Work is punishment for failing to procrastinate effectively.

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


[Haskell-cafe] Exportable and importable instances

2011-01-07 Thread Marco Túlio Gontijo e Silva
Hi.

I'm planning to propose a language extension for Haskell to make it possible to
control the visibility of type class instances in module export and import
lists as a research project.  I'm planning to implement this in GHC.  I've
already mentioned it in #...@irc.freenode.net and got interesting comments from
tibbe and quicksilver.

I'd be glad to receive more feedback on the idea.  If you have any
comments, please reply to this thread or mail me individually, at your will.

Greetings.
-- 
marcot
http://marcot.eti.br/
[Flattr=54498]


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


Re: [Haskell-cafe] UTF-8 BOM

2011-01-07 Thread Simon Marlow

On 06/01/2011 05:44, Mark Lentczner wrote:

On Jan 4, 2011, at 5:41 PM, Antoine Latter wrote:


Are you thinking that the BOM should be automatically stripped
from UTF8 text at some low level, if present?


It should not. Wether or not a U+FFEF can be stripped depends on
context in which it is found. There is no way that lower level code,
even file primitives, can know this context.


I'm thinking that it would be correct behavior to drop the BOM
from the start of a UTF8 stream, even at a pretty low level. The
FAQ seems to allow it as a means of identifying the stream as UTF8
(although it isn't a reliable means of identifying a stream as
UTF8).


§3.9 and §3.10 of the Unicode standard go into more depth on the
issue and make things more clear. A leading U+FFEF is considered "not
part of the text", and dropped, only in the case that the encoding is
UTF-16 or UTF-32. In all other cases (including the -BE and -LE
variants of UTF-16 and UTF-32) the U+FFEF character is retained.

The FAQ states that a leading byte sequence of EF BB BF in a stream
indicates that the stream is UTF-8, though it doesn't go so far as to
say that it can be stripped. Since Unicode doesn't want to encourage
the use of BOM in UTF-8 (see end of §3.10), I imagine they don't want
to promulgate it as a useful encoding indicator.

So, it might be reasonable that when opening a file in UTF-16 mode
(not UTF-16BE or UTF-16LE), that the system should read the initial
bytes, determine the byte order, and remove the BOM if present[1].
But it isn't safe or correct to do this for UTF-8.


This is exactly what the built-in System.IO.utf16 codec does.  There's 
also a utf8_bom which behaves like UTF8 except that it strips an 
optional leading BOM when reading and emits a BOM when writing.


Cheers,
Simon

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


Re: [Haskell-cafe] HDBC, postgresql, bytestrings and embedded NULLs

2011-01-07 Thread Michael Snoyman
On Fri, Jan 7, 2011 at 11:44 AM, Iustin Pop  wrote:
> Hi all,
>
> It seems that (at least) the postgresql bindings do not allow pure
> binary data.
>
> I have a simple table:
>
>  debug=# create table test (name bytea);
>
> byteas seems to be the backing type on the DB side for bytestrings.
>
> and then I run this:
>
>  import Database.HDBC.PostgreSQL
>  import Database.HDBC
>  import Data.ByteString
>
>  main = do
>    db <- connectPostgreSQL "dbname=debug"
>    stmt <- prepare db "INSERT INTO test (name) VALUES($1)"
>    execute stmt [toSql $ pack [0]]
>    execute stmt [toSql $ pack [65, 0, 66]]
>    commit db
>
>
> What happens is that the inserted string is cut-off at the first NULL
> value: the first row is empty, and the second row contains just "A".
>
> http://www.postgresql.org/docs/8.4/static/datatype-binary.html says:
>
> “When entering bytea values, octets of certain values must be escaped
> (but all octet values can be escaped) when used as part of a string
> literal in an SQL statement. In general, to escape an octet, convert it
> into its three-digit octal value and precede it by two backslashes”, and
> continues to list that NULL should be quoted as E'\\000'. However, I
> find no such quoting in the HDCB.Postgresql sources.
>
> Anyone else stumbled on this?
>
> thanks,
> iustin
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>

Yes, I had a bug reported in persistent-postgresql that I traced back
to this bug. I reported the bug, but never heard a response. Frankly,
if I had time, I would write a low-level PostgreSQL binding so I could
skip HDBC entirely.

Michael

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


[Haskell-cafe] HDBC, postgresql, bytestrings and embedded NULLs

2011-01-07 Thread Iustin Pop
Hi all,

It seems that (at least) the postgresql bindings do not allow pure
binary data.

I have a simple table:

  debug=# create table test (name bytea);

byteas seems to be the backing type on the DB side for bytestrings.

and then I run this:

  import Database.HDBC.PostgreSQL
  import Database.HDBC
  import Data.ByteString
  
  main = do
db <- connectPostgreSQL "dbname=debug"
stmt <- prepare db "INSERT INTO test (name) VALUES($1)"
execute stmt [toSql $ pack [0]]
execute stmt [toSql $ pack [65, 0, 66]]
commit db
  

What happens is that the inserted string is cut-off at the first NULL
value: the first row is empty, and the second row contains just "A".

http://www.postgresql.org/docs/8.4/static/datatype-binary.html says:

“When entering bytea values, octets of certain values must be escaped
(but all octet values can be escaped) when used as part of a string
literal in an SQL statement. In general, to escape an octet, convert it
into its three-digit octal value and precede it by two backslashes”, and
continues to list that NULL should be quoted as E'\\000'. However, I
find no such quoting in the HDCB.Postgresql sources.

Anyone else stumbled on this?

thanks,
iustin

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


Re: [Haskell-cafe] Problem on overlapping instances

2011-01-07 Thread Magicloud Magiclouds
I agree, but with a slight difference. Since I am so lazy, if Binary
fits, like 80% of my requirements, for example this case, only
[String] is not OK. I'd like to reuse it with a little modification
made by myself, rather than re-write almost the whole of it.
But for Data.Binary, I think this problem is simple. Since it cannot
be derivinged, making extra function for [String] won't make the
further usage of my library complex.

On Fri, Jan 7, 2011 at 11:32 AM, Antoine Latter  wrote:
> Hello,
>
> I only use the 'Binary' class when I don't care about the specifics of
> the serialization format, only that it be reasonably fast, compact and
> stable.
>
> When I need to comply with some particular format I use the functions
> in Data.Binary.Builder and Data.Binary.Get directly. Sometimes I make
> my own Serialize/Deserialize classes if I think it will be helpful.
>
> But I do look at the source for the instances of the 'Binary' class
> for inspiration!
>
> Take care,
> Antoine
>
> On Wed, Jan 5, 2011 at 2:24 AM, Magicloud Magiclouds
>  wrote:
>> Hi,
>>  I am using Data.Binary which defined "instance Binary a => Binary
>> [a]". Now I need to define "instance Binary [String]" to make
>> something special for string list.
>>  How to make it work? I looked into the chapter of
>> overlappinginstances, nothing works.
>> --
>> 竹密岂妨流水过
>> 山高哪阻野云飞
>>
>> ___
>> 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