Re: [Haskell-cafe] Why is Haskell flagging this?

2010-12-22 Thread Ryan Ingram
Huh, that's weird, I just copy and pasted this into a new file and it worked
for me.

I did prepend the line

module RandTest where

  -- ryan

On Tue, Dec 21, 2010 at 6:43 PM, michael rice nowg...@yahoo.com wrote:

 I changed your die function to rollDie in function roll2Dice (I assume
 that's what you meant) but get the errors listed below.

 Michael

 

 import Control.Monad.State
 import Control.Monad

 import System.Random

 type GeneratorState = State StdGen

 genRandom :: Random a = GeneratorState a
 genRandom = State random

 -- similar
 genRandomR :: Random a = (a,a) - GeneratorState a
 genRandomR = State . randomR

 rollDie :: GeneratorState Int
 rollDie = genRandomR (1,6)

 roll2Dice :: GeneratorState Int
 roll2Dice = liftM2 (+) rollDie rollDie

 ===

 Prelude :l craps7
 [1 of 1] Compiling Main ( craps7.hs, interpreted )

 craps7.hs:7:12: Not in scope: data constructor `State'

 craps7.hs:11:13: Not in scope: data constructor `State'

 Failed, modules loaded: none.
 Prelude


 --- On *Tue, 12/21/10, Ryan Ingram ryani.s...@gmail.com* wrote:


 From: Ryan Ingram ryani.s...@gmail.com

 Subject: Re: [Haskell-cafe] Why is Haskell flagging this?
 To: michael rice nowg...@yahoo.com
 Cc: David Leimbach leim...@gmail.com, Daniel Fischer 
 daniel.is.fisc...@googlemail.com, haskell-cafe@haskell.org
 Date: Tuesday, December 21, 2010, 7:00 PM

 First, let's make some useful operations in your GeneratorState monad:

 -- State :: (s - (a,s)) - State s a
 -- random :: Random a = StdGen - (a, StdGen)
 genRandom :: Random a = GeneratorState a
 genRandom = State random

 -- similar
 genRandomR :: Random a = (a,a) - GeneratorState a
 genRandomR = State . randomR

 rollDie :: GeneratorState Int
 rollDie = genRandomR (1,6)

 roll2Dice :: GeneratorState Int
 roll2Dice = liftM2 (+) die die

 These can be used to simplify a lot of the code here.

   -- ryan


 On Fri, Dec 17, 2010 at 5:55 PM, michael rice 
 nowg...@yahoo.comhttp://mc/compose?to=nowg...@yahoo.com
  wrote:

 Paul Graham refers to all those features as orthogonality (On Lisp, pg.
 63) and you're right, Haskell has it in spades, but it takes time to
 understand all of it and even more time to use it effectively. One almost
 needs a checklist.

 But I think I'm catching on. I programmed this craps simulation last week.
 It's a problem from Problems For Computer Solution, Gruenberger  Jaffray,
 1965, The RAND Corp.

 import Control.Monad.State
 import System.Random

 type GeneratorState = State StdGen
 data Craps a = Roll a | Win a | Lose a deriving (Show)

 f :: Craps [Int] - GeneratorState (Craps [Int])
 f (Roll []) = do g0 - get
  let (d1,g1) = randomR (1,6) g0
  (d2,g2) = randomR (1,6) g1
  t1 = d1+d2
  put g2
  case t1 of
 2 - return (Lose [t1])
 3 - return (Lose [t1])
 7 - return (Win [t1])
 11 - return (Win [t1])
 _ - do g2 - get
 let (d3,g3) = randomR (1,6) g2
 (d4,g4) = randomR (1,6) g3
 t2 = d3+d4
 put g4
 if t2 == t1
   then do
 return (Win [t1,t2])
   else
 if t2 == 7
   then do
 return (Lose [t1,t2])
   else
 f (Roll [t2,t1])
 f (Roll l) = do g0 - get
 let (d1,g1) = randomR (1,6) g0
 (d2,g2) = randomR (1,6) g1
 t = d1+d2
 if t == (last l)
   then do
 put g2
 return (Win (reverse (t:l)))
   else
 if t == 7
   then do
 put g2
 return (Lose (reverse (t:l)))
   else do
 put g2
 f (Roll (t:l))

 progressive (z@(x:xs),n) (Win _) = let b = x + (last xs)
in (init xs,n+b)
 progressive (z@(x:xs),n) (Lose _) = let b = x + (last xs)
 in (z ++ [b],n-b)

 *Main let r = evalState (sequence $ replicate 6 (f (Roll []))) (mkStdGen
 987)
 *Main r
 [Win [8,12,10,3,8],Win [5,9,10,11,12,11,8,9,5],Win [7],Lose [9,7],Win
 [5,5],Win [5,2,6,4,6,8,5]]
 *Main foldl progressive ([1..10],0) r
 ([6],49)

 Function f generates the roll cycle outcomes which are then folded with the
 progressive betting system.

 In the final answer, the [6] is what's left of the original betting list
 [1..10]. The betting list is used to determine the bet: always bet the
 (first + last) of 

Re: [Haskell-cafe] [darcs-users] Darcs failure

2010-12-22 Thread Eric Kow
Andrew,

Thanks for your report. Indeed, please direct future reports
to darcs-users or b...@darcs.net

  darcs: bug at src/URL.hs:246 compiled Sep 12 2010 20:24:56
  Another possible bug in URL.waitNextUrl:  curl_multi_perform() - no running
  handles
  See http://wiki.darcs.net/BugTracker/Reporting for help on bug reporting.

I think this was resolved in darcs-2.5 [1].  If not, it's at least
resolved in what will become Darcs 2.8.

Unfortunately, our release notes don't mention it [2], so I'm not 100%
sure

Cheers,

Eric

[1] http://bugs.darcs.net/issue1770
[2] http://wiki.darcs.net/Releases/2.5

-- 
Eric Kow http://www.nltg.brighton.ac.uk/home/Eric.Kow
For a faster response, try +44 (0)1273 64 2905 or
xmpp:ko...@jabber.fr (Jabber or Google Talk only)


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


Re: [Haskell-cafe] Rendering of hask in new wiki (MSIE6)

2010-12-22 Thread David Virebayre
 Statistics from A tour of the Haskell Monad functions (on my site), after
 15.351 pageviews:

I find it surprising that nobody using google chrome ever browsed your site.

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


Re: [Haskell-cafe] Why is Haskell flagging this?

2010-12-22 Thread Daniel Fischer
On Wednesday 22 December 2010 12:03:01, Ryan Ingram wrote:
 Huh, that's weird, I just copy and pasted this into a new file and it
 worked for me.

As a guess, you have mtl-1.*?
In mtl-2.*, State s is made a type synonym for StateT s Identity, so 
there's no longer a data constructor State.

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


Re: [Haskell-cafe] [darcs-users] Darcs failure

2010-12-22 Thread Andrew Coppin

On 22/12/2010 11:08 AM, Eric Kow wrote:

Andrew,

Thanks for your report. Indeed, please direct future reports
to darcs-users or b...@darcs.net


That would require me to sign up to yet another mailing list just to 
report one bug. And given that we're talking about a prebuilt binary 
being trivially broken out-of-the-box, presumably it's already a widely 
known bug.



I think this was resolved in darcs-2.5 [1].  If not, it's at least
resolved in what will become Darcs 2.8.

Unfortunately, our release notes don't mention it [2], so I'm not 100%
sure


Right. So 2.4.4 is broken, and I just need a newer version?

Presumably the only way to do that would be to build one. (?) As I 
understand it, apt-get and similar tools are designed to 100% prevent 
you having any choice whatsoever over the version numbers of stuff that 
gets installed. On the other hand, presumably cabal-install will happily 
build anything I ask it to...



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


[Haskell-cafe] implementing RealFloat decodeFloat

2010-12-22 Thread Claude Heiland-Allen

Hi everyone,

I've been working on [0] Haskell bindings for [1] libqd for [2] 
double-double and quad-double arithmetic, and have been struggling to 
implement [3] RealFloat, in particular [4] decodeFloat, mostly because 
of its postcondition but also some issues relating to variable precision:


---8---
If decodeFloat x yields (m,n), then x is equal in value to m*b^^n, where 
b is the floating-point radix, and furthermore, either m and n are both 
zero or else b^(d-1) = m  b^d, where d is the value of floatDigits x. 
In particular, decodeFloat 0 = (0,0).

---8---

(BTW: that should probably really be ... = abs m  ...; perhaps this 
code could be added to the report and/or documentation, if it is correct:


  validDecode :: RealFloat f = f - Bool
  validDecode f = case decodeFloat f of
(0,0) - True
(m, e) - b^(d-1) = abs m  abs m  b^d
where
  b = floatRadix f
  d = floatDigits f

)

The double-double and quad-double types do not have a fixed precision, 
though they do have a fixed minimum precision: this means that 
decodeFloat will (in general) lose some precision.  This is because for 
example in:


  data DoubleDouble = DoubleDouble !CDouble !CDouble
  dd = DoubleDouble a b

the semantics are that dd = a + b, with |a||b|; coupled with the 
IEEE implicit leading 1 bit, this means that there may be large gaps 
between exponents: for example: 1 + 0.5**100 :: DoubleDouble.


So far I've got a mostly working implementation thus:

  decodeFloat !(DoubleDouble a b) =
case (decodeFloat a, decodeFloat b) of
  ((0, 0), (0, 0)) - (0, 0)
  ((0, 0), (m, e)) - (m `shiftL` f, e - f)
  ((m, e), (0, 0)) - (m `shiftL` f, e - f)
  ((m1, e1), (m2, e2)) -
let fixup m e =
  if m  mMin
then fixup (m `shiftL` 1) (e - 1)
else if m = mMax
   then fixup (m `shiftR` 1) (e + 1)
   else (m, e)
mMin = 1 `shiftL` (ff - 1)
mMax = 1 `shiftL` ff
ff = floatDigits (0 :: DoubleDouble)
g = e1 - e2 - f
in  fixup ((m1 `shiftL` f) + (m2 `shiftR` g)) (e1 - f)
where
  f = floatDigits (0 :: CDouble)

This does meet the postcondition as specified (which leads to breakage 
in other RealFloat methods), but has a recursion with no termination 
proof (so far), and is lossy in general:


   let check f = uncurry encodeFloat (decodeFloat f) == f
   check (1 + 0.5 ** 120 :: DoubleDouble)
  False

It does however seem to meet a weaker condition:

   let check2 f = (decodeFloat . (`asTypeOf` f) . uncurry encodeFloat 
. decodeFloat $ f) == decodeFloat f

   check2 (1 + 0.5 ** 120 :: DoubleDouble)
  True


Questions:

1. Is this weaker condition likely to be good enough in practice?
2. Can my implementation of decodeFloat be simplified?

Thanks for any insights,


Claude

[0] http://hackage.haskell.org/package/qd
[1] http://crd.lbl.gov/~dhbailey/mpdist/
[2] http://crd.lbl.gov/~dhbailey/dhbpapers/arith15.pdf
[3] 
http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.html#t:RealFloat
[4] 
http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.html#v:decodeFloat


--
http://claudiusmaximus.goto10.org

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


[Haskell-cafe] ANNOUNCE: storable-endian

2010-12-22 Thread Eugene Kirpichov
Hi cafe,

I've released storable-endian
http://hackage.haskell.org/package/storable-endian

It defines types like {{Int,Word}{16,32,64},Double,Float}{LE,BE} (for
example Int32BE) etc. with a corresponding Storable instance.

It is needed for binary interoperability with libraries or network
protocols with fixed endianness. Hope you find it useful.

-- 
Eugene Kirpichov
Senior Software Engineer,
Grid Dynamics http://www.griddynamics.com/

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


[Haskell-cafe] Windows Haskell Platform download link is broken

2010-12-22 Thread Aaron Gray
Windows Haskell Platform download link goes nowhere :-

http://hackage.haskell.org/platform/windows.html

The Download Haskell for Windows is broken :-


http://lambda.galois.com/hp-tmp/2010.2.0.0/HaskellPlatform-2010.2.0.0-setup.exe

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


[Haskell-cafe] Missing Parsec library in latest stable GHC

2010-12-22 Thread Aaron Gray
Missing Parsec library :-

scheme.o(.text+0x4fa):fake: undefined reference to
`parseczm2zi1zi0zi0_TextziParserCombinatorsziParsecziCombinator_skipMany1_closure'
scheme.o(.text+0x501):fake: undefined reference to
`parseczm2zi1zi0zi0_TextziPaserCombinatorsziParsecziChar_space_closure'
scheme.o(.text+0x5c2):fake: undefined reference to
`parseczm2zi1zi0zi0_TextziParserCombinatorsziParsecziChar_oneOf_closure'
scheme.o(.text+0x63a):fake: undefined reference to
`mtlzm1zi1zi0zi0_ControlziMonadziTrans_zdf1_closure'

GHC from :-

http://www.haskell.org/ghc/dist/stable/dist/


ghc-7.0.1.20101221-i386-windows.exehttp://www.haskell.org/ghc/dist/stable/dist/ghc-7.0.1.20101221-i386-windows.exe

and earlier.

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


[Haskell-cafe] Latest Haskell Platform for Windows

2010-12-22 Thread Aaron Gray
Could someone please point me at a copy of the latest Haskell platform or a
working GHC please.

Many thanks in advance,

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


Re: [Haskell-cafe] Latest Haskell Platform for Windows

2010-12-22 Thread Jonas Almström Duregård
Maybe this one:
http://hackage.haskell.org/platform/2010.2.0.0/HaskellPlatform-2010.2.0.0-setup.exe

/J

On 22 December 2010 17:15, Aaron Gray aaronngray.li...@gmail.com wrote:
 Could someone please point me at a copy of the latest Haskell platform or a
 working GHC please.
 Many thanks in advance,
 Aaron

 ___
 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] Missing Parsec library in latest stable GHC

2010-12-22 Thread Antoine Latter
What commands did you enter to produce this error?

Ahanks,
Antoine

On Wed, Dec 22, 2010 at 9:54 AM, Aaron Gray aaronngray.li...@gmail.com wrote:
 Missing Parsec library :-
 scheme.o(.text+0x4fa):fake: undefined reference to
 `parseczm2zi1zi0zi0_TextziParserCombinatorsziParsecziCombinator_skipMany1_closure'
 scheme.o(.text+0x501):fake: undefined reference to
 `parseczm2zi1zi0zi0_TextziPaserCombinatorsziParsecziChar_space_closure'
 scheme.o(.text+0x5c2):fake: undefined reference to
 `parseczm2zi1zi0zi0_TextziParserCombinatorsziParsecziChar_oneOf_closure'
 scheme.o(.text+0x63a):fake: undefined reference to
 `mtlzm1zi1zi0zi0_ControlziMonadziTrans_zdf1_closure'
 GHC from :-
     http://www.haskell.org/ghc/dist/stable/dist/
     ghc-7.0.1.20101221-i386-windows.exe
 and earlier.
 Aaron

 ___
 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] Latest Haskell Platform for Windows

2010-12-22 Thread Don Stewart
aaronngray.lists:
Could someone please point me at a copy of the latest Haskell platform or
a working GHC please.
Many thanks in advance,

The links on haskell.org/platform should work (there was a domain
change, so you'll no longer see lambda.galois.com links).

-- Don

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


Re: [Haskell-cafe] Latest Haskell Platform for Windows

2010-12-22 Thread Aaron Gray
On 22 December 2010 16:41, Don Stewart d...@galois.com wrote:

 aaronngray.lists:
 Could someone please point me at a copy of the latest Haskell platform
 or
 a working GHC please.
 Many thanks in advance,

 The links on haskell.org/platform should work (there was a domain
 change, so you'll no longer see lambda.galois.com links).


Okay, thanks. I obviously came along at the wrong time :)

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


Re: [Haskell-cafe] Missing Parsec library in latest stable GHC

2010-12-22 Thread Aaron Gray
On 22 December 2010 16:27, Antoine Latter aslat...@gmail.com wrote:

 What commands did you enter to produce this error?


ghc scheme.hs

I am still getting this on the 2010 2.0.0 release.

Aaron



 Ahanks,
 Antoine

 On Wed, Dec 22, 2010 at 9:54 AM, Aaron Gray aaronngray.li...@gmail.com
 wrote:
  Missing Parsec library :-
  scheme.o(.text+0x4fa):fake: undefined reference to
 
 `parseczm2zi1zi0zi0_TextziParserCombinatorsziParsecziCombinator_skipMany1_closure'
  scheme.o(.text+0x501):fake: undefined reference to
  `parseczm2zi1zi0zi0_TextziPaserCombinatorsziParsecziChar_space_closure'
  scheme.o(.text+0x5c2):fake: undefined reference to
  `parseczm2zi1zi0zi0_TextziParserCombinatorsziParsecziChar_oneOf_closure'
  scheme.o(.text+0x63a):fake: undefined reference to
  `mtlzm1zi1zi0zi0_ControlziMonadziTrans_zdf1_closure'
  GHC from :-
  http://www.haskell.org/ghc/dist/stable/dist/
  ghc-7.0.1.20101221-i386-windows.exe
  and earlier.
  Aaron
 
  ___
  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] Missing Parsec library in latest stable GHC

2010-12-22 Thread Antoine Latter
ghc doesn't, by default, go searching for packages to link in to the
resulatant executable..

If you try 'ghc --make scheme.hs' your example will work better.

You can also specify what to link manually, but --make works pretty
well most of the time.

In ghc version 7 '--make' is the default, but until that's more widely
distributed you'll want to get used to using the switch.

Take care,
Antoine

On Wed, Dec 22, 2010 at 10:36 AM, Aaron Gray aaronngray.li...@gmail.com wrote:
 On 22 December 2010 16:27, Antoine Latter aslat...@gmail.com wrote:

 What commands did you enter to produce this error?


 ghc scheme.hs
 Aaron


 Ahanks,
 Antoine

 On Wed, Dec 22, 2010 at 9:54 AM, Aaron Gray aaronngray.li...@gmail.com
 wrote:
  Missing Parsec library :-
  scheme.o(.text+0x4fa):fake: undefined reference to
 
  `parseczm2zi1zi0zi0_TextziParserCombinatorsziParsecziCombinator_skipMany1_closure'
  scheme.o(.text+0x501):fake: undefined reference to
  `parseczm2zi1zi0zi0_TextziPaserCombinatorsziParsecziChar_space_closure'
  scheme.o(.text+0x5c2):fake: undefined reference to
  `parseczm2zi1zi0zi0_TextziParserCombinatorsziParsecziChar_oneOf_closure'
  scheme.o(.text+0x63a):fake: undefined reference to
  `mtlzm1zi1zi0zi0_ControlziMonadziTrans_zdf1_closure'
  GHC from :-
      http://www.haskell.org/ghc/dist/stable/dist/
      ghc-7.0.1.20101221-i386-windows.exe
  and earlier.
  Aaron
 
  ___
  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] Rendering of hask in new wiki (MSIE6)

2010-12-22 Thread Henk-Jan van Tuyl
On Wed, 22 Dec 2010 13:22:07 +0100, David Virebayre  
dav.vire+hask...@gmail.com wrote:


Statistics from A tour of the Haskell Monad functions (on my site),  
after

15.351 pageviews:


I find it surprising that nobody using google chrome ever browsed your  
site.




That is indeed strange; below statistics for the same page from a  
different statistics provider:


Period: 2009-07-08 .. 2010-12-22 (the total period that  
this counter is active)

Page views: 11.164
Unique page views:  10.380
Number of new visitors:  6.358

Browsers (18 browsers were used):

   Page Unique page
   viewsviews
1.   Firefox   5.4175.015
2.   Chrome2.2192.052
3.   Opera 1.2291.188
4.   Safari  811  747
5.   Mozilla 689  646
6.   Internet Explorer   665  608
7.   Konqueror64   58
8.   Camino   39   39
9.   Uzbl  75
10.  Midori54


Operating Systems (15 operating systems were used):

1.  Windows4.7764.443
2.  Linux  4.7014.378
3.  Macintosh  1.5171.410
4.  FreeBSD   58   49
5.  iPhone23   20
6.  Android   16   13
7.  SunOS 15   12
8.  (not set) 12   11
9.  NetBSD 86
10. iPad   77



Regards,
Henk-Jan van Tuyl


--
http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
--

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


Re: [Haskell-cafe] Missing Parsec library in latest stable GHC

2010-12-22 Thread Daniel Fischer
On Wednesday 22 December 2010 16:54:04, Aaron Gray wrote:
 Missing Parsec library :-

 scheme.o(.text+0x4fa):fake: undefined reference to
 `parseczm2zi1zi0zi0_TextziParserCombinatorsziParsecziCombinator_skipMany
1_closure' scheme.o(.text+0x501):fake: undefined reference to
 `parseczm2zi1zi0zi0_TextziPaserCombinatorsziParsecziChar_space_closure'
 scheme.o(.text+0x5c2):fake: undefined reference to
 `parseczm2zi1zi0zi0_TextziParserCombinatorsziParsecziChar_oneOf_closure'
 scheme.o(.text+0x63a):fake: undefined reference to
 `mtlzm1zi1zi0zi0_ControlziMonadziTrans_zdf1_closure'

 GHC from :-

 http://www.haskell.org/ghc/dist/stable/dist/


 ghc-7.0.1.20101221-i386-windows.exehttp://www.haskell.org/ghc/dist/stab
le/dist/ghc-7.0.1.20101221-i386-windows.exe

 and earlier.

 Aaron

Since 6.8 iirc, GHC no longer comes with parsec, you have to install the 
package yourself if you want to use it,

cabal install parsec

also mtl is no longer one of the libraries that come with GHC, 

cabal install mtl

HTH,
Daniel

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


Re: [Haskell-cafe] Functor = Applicative = Monad

2010-12-22 Thread Simon Marlow

On 14/12/2010 08:35, Isaac Dupree wrote:

On 12/14/10 03:13, John Smith wrote:

I would like to formally propose that Monad become a subclass of
Applicative, with a call for consensus by 1 February. The change is
described on the wiki at
http://haskell.org/haskellwiki/Functor-Applicative-Monad_Proposal,


That page isn't written as a proposal yet, it's written as a bunch of
ideas. I would be happy to see something along the lines of Bas van
Dijk's work
http://permalink.gmane.org/gmane.comp.lang.haskell.libraries/14740 .


This is a proposal with far-reaching consequences, and with several 
alternative designs. I'm not sure I understand all the tradeoffs.  Some 
parts of the proposal are orthogonal to the rest (e.g. changing fmap to 
map), and should probably be considered separately.


Could someone please write a detailed proposal, enumerating all the pros 
and cons, and the rationale for this design compared to other designs?


Cheers,
Simon

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


Re: [Haskell-cafe] Missing Parsec library in latest stable GHC

2010-12-22 Thread Aaron Gray
On 22 December 2010 16:47, Antoine Latter aslat...@gmail.com wrote:

 ghc doesn't, by default, go searching for packages to link in to the
 resulatant executable..

 If you try 'ghc --make scheme.hs' your example will work better.


Are great, thanks a lot.


 You can also specify what to link manually, but --make works pretty
 well most of the time.

 In ghc version 7 '--make' is the default, but until that's more widely
 distributed you'll want to get used to using the switch.


Yes it was linking before I upgraded GHC, hence my confusion :)

Many thanks Antoine,

Aaron



 Take care,
 Antoine

 On Wed, Dec 22, 2010 at 10:36 AM, Aaron Gray aaronngray.li...@gmail.com
 wrote:
  On 22 December 2010 16:27, Antoine Latter aslat...@gmail.com wrote:
 
  What commands did you enter to produce this error?
 
 
  ghc scheme.hs
  Aaron
 
 
  Ahanks,
  Antoine
 
  On Wed, Dec 22, 2010 at 9:54 AM, Aaron Gray aaronngray.li...@gmail.com
 
  wrote:
   Missing Parsec library :-
   scheme.o(.text+0x4fa):fake: undefined reference to
  
  
 `parseczm2zi1zi0zi0_TextziParserCombinatorsziParsecziCombinator_skipMany1_closure'
   scheme.o(.text+0x501):fake: undefined reference to
  
 `parseczm2zi1zi0zi0_TextziPaserCombinatorsziParsecziChar_space_closure'
   scheme.o(.text+0x5c2):fake: undefined reference to
  
 `parseczm2zi1zi0zi0_TextziParserCombinatorsziParsecziChar_oneOf_closure'
   scheme.o(.text+0x63a):fake: undefined reference to
   `mtlzm1zi1zi0zi0_ControlziMonadziTrans_zdf1_closure'
   GHC from :-
   http://www.haskell.org/ghc/dist/stable/dist/
   ghc-7.0.1.20101221-i386-windows.exe
   and earlier.
   Aaron
  
   ___
   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] [darcs-users] Darcs failure

2010-12-22 Thread Jason Dagit
On Wed, Dec 22, 2010 at 5:09 AM, Andrew Coppin
andrewcop...@btinternet.comwrote:

 On 22/12/2010 11:08 AM, Eric Kow wrote:

 Andrew,

 Thanks for your report. Indeed, please direct future reports
 to darcs-users or b...@darcs.net


 That would require me to sign up to yet another mailing list just to report
 one bug.


Just so you know, that's not true in this case.  Anyone can send to
b...@darcs and darcs-users was still using human moderators last I checked.

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


Re: [Haskell-cafe] Missing Parsec library in latest stable GHC

2010-12-22 Thread Aaron Gray
On 22 December 2010 16:51, Daniel Fischer
daniel.is.fisc...@googlemail.comwrote:

 On Wednesday 22 December 2010 16:54:04, Aaron Gray wrote:
  Missing Parsec library :-
 
  scheme.o(.text+0x4fa):fake: undefined reference to
  `parseczm2zi1zi0zi0_TextziParserCombinatorsziParsecziCombinator_skipMany
 1_closure' scheme.o(.text+0x501):fake: undefined reference to
  `parseczm2zi1zi0zi0_TextziPaserCombinatorsziParsecziChar_space_closure'
  scheme.o(.text+0x5c2):fake: undefined reference to
  `parseczm2zi1zi0zi0_TextziParserCombinatorsziParsecziChar_oneOf_closure'
  scheme.o(.text+0x63a):fake: undefined reference to
  `mtlzm1zi1zi0zi0_ControlziMonadziTrans_zdf1_closure'
 
  GHC from :-
 
  http://www.haskell.org/ghc/dist/stable/dist/
 
 
  ghc-7.0.1.20101221-i386-windows.exehttp://www.haskell.org/ghc/dist/stab
 le/dist/ghc-7.0.1.20101221-i386-windows.exe
 
  and earlier.
 
  Aaron

 Since 6.8 iirc, GHC no longer comes with parsec, you have to install the
 package yourself if you want to use it,

 cabal install parsec


This does not seem to be needed.

import Text.ParserCombinators.Parsec

seems fine.



 also mtl is no longer one of the libraries that come with GHC,

 cabal install mtl


What is mtl ?

Thanks,

Aaron



 HTH,
 Daniel

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


Re: [Haskell-cafe] Why is Haskell flagging this?

2010-12-22 Thread Ryan Ingram
Interesting.  In that case,

state f = StateT $ \s - Identity (f s)

allows state to replace State in that code.

On Wed, Dec 22, 2010 at 4:56 AM, Daniel Fischer
daniel.is.fisc...@googlemail.com wrote:
 On Wednesday 22 December 2010 12:03:01, Ryan Ingram wrote:
 Huh, that's weird, I just copy and pasted this into a new file and it
 worked for me.

 As a guess, you have mtl-1.*?
 In mtl-2.*, State s is made a type synonym for StateT s Identity, so
 there's no longer a data constructor State.


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


Re: [Haskell-cafe] Infinite lists in real world programs

2010-12-22 Thread Yves Parès
Patai, I read your paper on Elerea. It wasn't easy :), but I think I got the
picture.
So I would have 2 questions :

I made a simple function which turns an infinite list into a signal :

fromList :: [a] - SignalGen (Signal a)
fromList xs =
  stateful xs tail = memo . fmap head

1) It does what I want, but is it the good way to do it?
2) Since the returned signal may be used in several places and since I
obtain it through the generic fmap (and not through an Elerea primitive), I
guessed I had to memo it instead of simply using return. Did I guess
right?

3) Concerning the functionnality added by the Param implementation, I have
the impression that the same can be achieved through the use of an external
signal in Simple (*). Am I right? If so, why did you make the Param
alternative?

(*) (ext, sink) - external 'a'
driver - start $ someSigGen ext
sink 'b'
driver
sink 'c'
driver
sink 'd'
driver
etc...


2010/12/16 Patai Gergely patai_gerg...@fastmail.fm

  So in the result of (a = f), the first element is taken from the
  first element of applying f to the first element of a; the second
  element is the second element in the result of applying f to the second
  element of a; and so on.  Off the top of my head I am not sure what
  this corresponds to in terms of agents or where it would be useful,
  but I'm sure it must correspond to something interesting.
 In short, join corresponds to continuously sampling a stream of streams.
 In other words, it turns a higher-order stream into a dynamic data-flow
 network. That's exactly what the Elerea library [1] is good for: it
 allows you to do this in constant time instead of the quadratic cost of
 the pure implementation, but it forces you to traverse streams
 sequentially -- fortunately, that's exactly what you want to do most of
 the time. There is also a paper behind the library, which might help a
 bit in getting a clearer picture [2] (the paper also has an updated
 version in the process of being published).

 Gergely

 [1] http://hackage.haskell.org/package/elerea
 [2]
 http://sgate.emt.bme.hu/documents/patai/publications/PataiWFLP2010.pdf

 --
 http://www.fastmail.fm - One of many happy users:
  http://www.fastmail.fm/docs/quotes.html


 ___
 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] Matlab Style Logic Operations ala V1.*(V20) on Vectors and Matrices with HMatrix ??

2010-12-22 Thread gutti

Hi Henning, 

You definitly caught me on that little Germanism :-)

About Your comments - a lot to learn and take in, but it really helps. -
Thanks a lot.
I just manged to get the Matrix masking running code looks like (code A see
below). Two quick questions:

question 1.  u see the two commented lines I tried to get ur original line
running, but didn't know how to specify f

## Code 

import Numeric.LinearAlgebra
import Graphics.Plot

matrix1 = fromLists [[0 .. 5],[30 .. 35],[50 .. 55]]
matrix2 = fromLists [[-1,2],[-3,4],[5,-6]]

-- matrix1 = buildMatrix 3 4 ( (r,c) - fromIntegral r * fromIntegral c)
(34)
-- posPart v  =  mapVector (\a - if a=0 then a else 0) v 

-- function2map a1 a2 = (\a1 a2 - if a1=0 then a2/a1 else a1/a2)
matrixfunction x y = liftMatrix2 (zipVectorWith(\a1 a2 - if a2=0 then a1
else 0)) x y 

matrix3 = matrixfunction matrix1 matrix2

disp = putStr . disps 2
  
main = do 

  disp matrix1
  disp matrix2
--  disp matrix3
  mesh matrix1


#


question 2: - the compiler comes up with some weired data type problem --
ghci has no problem this line :

matrixTest_Fail.hs:5:10:
Ambiguous type variable `t' in the constraints:
  `Element t'
arising from a use of `fromLists' at matrixTest_Fail.hs:5:10-38
  `Num t' arising from the literal `1' at matrixTest_Fail.hs:5:22
Possible cause: the monomorphism restriction applied to the following:
  matrix2 :: Matrix t (bound at matrixTest_Fail.hs:5:0)
Probable fix: give these definition(s) an explicit type signature
  or use -XNoMonomorphismRestriction
 
## Code #

import Numeric.LinearAlgebra
import Graphics.Plot

matrix1 = fromLists [[1,2],[3,4],[5,6]]
matrix2 = fromLists [[1,2],[3,4],[5,6]]

disp = putStr . disps 2

main = do 

  disp matrix1

#
-- 
View this message in context: 
http://haskell.1045720.n5.nabble.com/Matlab-Style-Logic-Operations-ala-V1-V2-0-on-Vectors-and-Matrices-with-HMatrix-tp3312601p3315761.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


Re: [Haskell-cafe] Identity type

2010-12-22 Thread John Meacham
On Tue, Dec 14, 2010 at 10:31 AM, Pierre-Etienne Meunier
pierreetienne.meun...@gmail.com wrote:
 Is there something like an identity type, transparent to the type-checker, in 
 haskell ?
 For instance, I'm defining an interval arithmetic, with polynomials, 
 matrices, and all that... defined with intervals. The types are :

No, such a thing doesn't exist. In fact, it would make the type system
undecidable if it did exist. I only know this because a long while ago
I really wanted such a thing to exist then tried to work out the
consequences and realized it would break the type system. I have found
liberal use of 'newtype-deriving' has mitigated my need for it in the
specific cases I was interested in.

John

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


Re: [Haskell-cafe] [darcs-users] Darcs failure

2010-12-22 Thread Ivan Lazar Miljenovic
On 23 December 2010 00:09, Andrew Coppin andrewcop...@btinternet.com wrote:

 Presumably the only way to do that would be to build one. (?) As I
 understand it, apt-get and similar tools are designed to 100% prevent you
 having any choice whatsoever over the version numbers of stuff that gets
 installed. On the other hand, presumably cabal-install will happily build
 anything I ask it to...

Not all Linux package managers provide one version and one version
only (though admittedly most do).

-- 
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


Re: [Haskell-cafe] Proof in Haskell

2010-12-22 Thread Patrick Browne
On 22/12/2010 14:48, Artyom Shalkhakov wrote:
 ..Do you want to prove a property of
 a function formally, using some kind of formal logic?

I am aware that functional languages do not do proofs at term level, but
the motivation for my question is to get a precise reason why this is
so. The replies from the café have clearly articulated the reasons.

Thanks to all,
Pat






This message has been scanned for content and viruses by the DIT Information 
Services E-Mail Scanning Service, and is believed to be clean. http://www.dit.ie

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


Re: [Haskell-cafe] Matlab Style Logic Operations ala V1.*(V20) on Vectors and Matrices with HMatrix ??

2010-12-22 Thread Henning Thielemann


On Wed, 22 Dec 2010, gutti wrote:


question 1.  u see the two commented lines I tried to get ur original line
running, but didn't know how to specify f


What 'f' ? Do you mean

matrixfunction f x y = liftMatrix2 (zipVectorWith f) x y

?



## Code 

import Numeric.LinearAlgebra
import Graphics.Plot

matrix1 = fromLists [[0 .. 5],[30 .. 35],[50 .. 55]]
matrix2 = fromLists [[-1,2],[-3,4],[5,-6]]

-- matrix1 = buildMatrix 3 4 ( (r,c) - fromIntegral r * fromIntegral c)
(34)
-- posPart v  =  mapVector (\a - if a=0 then a else 0) v

-- function2map a1 a2 = (\a1 a2 - if a1=0 then a2/a1 else a1/a2)
matrixfunction x y = liftMatrix2 (zipVectorWith(\a1 a2 - if a2=0 then a1 else 
0)) x y




matrix3 = matrixfunction matrix1 matrix2

disp = putStr . disps 2

main = do

 disp matrix1
 disp matrix2
--  disp matrix3
 mesh matrix1


#


question 2: - the compiler comes up with some weired data type problem --
ghci has no problem this line :

matrixTest_Fail.hs:5:10:
   Ambiguous type variable `t' in the constraints:
 `Element t'
   arising from a use of `fromLists' at matrixTest_Fail.hs:5:10-38
 `Num t' arising from the literal `1' at matrixTest_Fail.hs:5:22
   Possible cause: the monomorphism restriction applied to the following:
 matrix2 :: Matrix t (bound at matrixTest_Fail.hs:5:0)
   Probable fix: give these definition(s) an explicit type signature
 or use -XNoMonomorphismRestriction

## Code #

import Numeric.LinearAlgebra
import Graphics.Plot

matrix1 = fromLists [[1,2],[3,4],[5,6]]
matrix2 = fromLists [[1,2],[3,4],[5,6]]


Before type inference can work, you need to fix the type of at least one 
number of a set of numbers with known equal type. E.g.



matrix1 = fromLists [[1,2],[3,4],[5,6::Double]]



or even better, add a type signature:

matrix1 :: Matrix Double

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


Re: [Haskell-cafe] ANNOUNCE: storable-endian

2010-12-22 Thread Henning Thielemann


On Wed, 22 Dec 2010, Eugene Kirpichov wrote:


Hi cafe,

I've released storable-endian
http://hackage.haskell.org/package/storable-endian

It defines types like {{Int,Word}{16,32,64},Double,Float}{LE,BE} (for
example Int32BE) etc. with a corresponding Storable instance.

It is needed for binary interoperability with libraries or network
protocols with fixed endianness. Hope you find it useful.


How about type constructors LittleEndian and BigEndian?

newtype LittleEndian a = LittleEndian a

Maybe using some type classes you can even get rid of Template Haskell and 
get plain Haskell 98?


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


Re: [Haskell-cafe] Data.Typeable TypeRep Ord instance.

2010-12-22 Thread John Meacham
On Sat, Dec 4, 2010 at 2:08 PM, Serguey Zefirov sergu...@gmail.com wrote:
 Why TypeRep does have equality and doesn't have ordering?

 It would be good to have that.

Yes, I have wanted that too. It would make maps from types to values
possible/efficient. There is a very critical path in jhc that use
type-indexed data structures that I have to implement a very hacky
workaround for no Ord instance for TypeRep

John

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


Re: [Haskell-cafe] ANNOUNCE: storable-endian

2010-12-22 Thread Henning Thielemann


On Thu, 23 Dec 2010, Henning Thielemann wrote:


On Wed, 22 Dec 2010, Eugene Kirpichov wrote:


It defines types like {{Int,Word}{16,32,64},Double,Float}{LE,BE} (for
example Int32BE) etc. with a corresponding Storable instance.


How about type constructors LittleEndian and BigEndian?

newtype LittleEndian a = LittleEndian a

Maybe using some type classes you can even get rid of Template Haskell and 
get plain Haskell 98?


Yes, I think you could have (given a module Data.Storable.LittleEndian as 
LE)


instance LE.Storable a = Storable (LittleEndian a) where
   sizeOf (LittleEndian a) = sizeOf a
   alignment (LittleEndian a) = alignment a
   peek p = fmap LittleEndian $ LE.peek p
   poke p (LittleEndian a) = LE.poke p a

class LE.Storable a where
   LE.peek :: Ptr a - IO a
   LE.poke :: Ptr a - a - IO ()

instance LE.Storable Word16 where
   LE.peek p = getWord16le (castPtr p)
   LE.poke p = putWord16le (castPtr p)

...

I find this much cleaner and simpler to extend to other types.

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


Re: [Haskell-cafe] Why is Haskell flagging this?

2010-12-22 Thread Ozgur Akgun
see also:
http://hackage.haskell.org/packages/archive/mtl/latest/doc/html/Control-Monad-State-Lazy.html#v:state

On 22 December 2010 20:02, Ryan Ingram ryani.s...@gmail.com wrote:

 Interesting.  In that case,

 state f = StateT $ \s - Identity (f s)

 allows state to replace State in that code.


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


Re: [Haskell-cafe] $ do?

2010-12-22 Thread Brandon S Allbery KF8NH
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 12/15/10 02:36 , Roman Cheplyaka wrote:
 Regarding the rationale, I'm not so sure and I'd like to hear an
 explanation from someone competent. But I assume it has something
 to do with the fact that if you supply a 'do' argument, you cannot
 supply any more arguments (because 'do' extends to the right as far as
 possible). Not that I'm convinced that it is a valid reason to prohibit
 such construct.

Hm?  do {...} would work, as would using indentation per usual layout rules
(the next argument would be indented no farther than the do).  It'd
certainly be more confusing to read, though.

- -- 
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 v2.0.10 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk0SsvUACgkQIn7hlCsL25XM6wCcDvu9G3fc9M5Vv6d2EKZ64X8t
k7YAn0hvoyq0KpmAAEyAD4HIWX8HsMTY
=11UF
-END PGP SIGNATURE-

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


Re: [Haskell-cafe] Behaviour of System.Directory.getModificationTime

2010-12-22 Thread Brandon S Allbery KF8NH
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 12/17/10 06:22 , Arnaud Bailly wrote:
 Thanks for your answers. I am a little bit surprised, I thought
 timestamps were on the milliseconds scale.

POSIX timestamps are seconds.

- -- 
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 v2.0.10 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk0Ss28ACgkQIn7hlCsL25XpygCgziZm1KyO+dP00ACtIrfsueJg
0dQAoI6hNz3oSmiIO2kAiXtRmowWwAg1
=wAHu
-END PGP SIGNATURE-

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


[Haskell-cafe] parsec2 vs. parsec3... again

2010-12-22 Thread Evan Laforge
Yeah, I know this has been discussed a number of times, but I have
some concrete questions I haven't seen asked before.  And the parsec
3 is now as fast as parsec 2 thing I've seen around doesn't seem to
be true for me.

I have an app that does a lot of parsing of small expressions.  It's
currently parsec2 operating on lots of little Texts (after an unpack,
of course).  A few parsing functions show up near the top of the
profile output, so I thought an obvious improvement would be to parse
Text directly and avoid the overhead and garbage of unpacking.  Since
parsec3 is now supposed to be as fast as parsec2 I thought I would
give it a try.  Parsec3 is 3.1.0, parsec 2 is 2.1.0.1:

parsec2, String:
total time  =   10.66 secs   (533 ticks @ 20 ms)
total alloc = 2,340,113,404 bytes  (excludes profiling overheads)

parsec3, String: (this is just after upgrading the library and editing
it to fix breakage from Parser being a type alias now)
total time  =   13.76 secs   (688 ticks @ 20 ms)
total alloc = 2,706,625,256 bytes  (excludes profiling overheads)

parsec3, Text: (wrote a Text instance similar to the one for
ByteString, updated imports, no longer unpacking to String)
total time  =   15.96 secs   (798 ticks @ 20 ms)
total alloc = 3,338,005,896 bytes  (excludes profiling overheads)

This is not very encouraging!  Especially strange is how Text
generates *more* allocation... I'd expect less since it doesn't unpack
all the Texts.  The parsing functions are no longer at the top of the
profile, but there are new 'unParser' and 'parsecMap' and 'parserBind'
up at or near the top.  'unParser' just looks like it's unwrapping the
Parsec newtype, so I don't fully understand how it's the most
expensive, but it's called on every bind so it does get called a lot.
There are no obvious super expensive ones, just lots and lots of them
that add up.  Parsec 3's unParser covers up the parsing function I
wrote, so it's now hard to tell what the expensive parsing function
actually is.

I've seen a few remarks that you can't just throw together parsers and
expect them to be fast, you have to profile them, but nothing on how
to actually interpret the results of profiling.

For instance, here's one of the main expensive parsers:

p_unsigned_float :: P.CharParser st Double
p_unsigned_float = do
i - P.many P.digit
f - P.option  (P.char '.'  P.many1 P.digit)
if (null i  null f) then P.pzero else do
let int = List.foldl'
(\total c - 10 * total + fromIntegral (Char.digitToInt c)) 0 i
frac = foldr
(\c total - (total + fromIntegral (Char.digitToInt c)) / 10) 0 f
return (int + frac)

There's an obvious problem where I get the digits as a String and then
parse that with list functions, but I can't see any way to get parsec
to return a chunk of Text.  This is roughly how parsec itself parses
numbers, in Text.Parsec.Token.

So, my current options are either figure out some way to speed up
parsec3+Text, revert to parsec2+String and give up, or try an entirely
different parsing library.  I've heard attoparsec is fast but I'd have
to switch to utf8 bytestring which is a big change, and Text seems
like the more correct choice anyway.

Any ideas or experience?

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


Re: [Haskell-cafe] Why is Haskell flagging this?

2010-12-22 Thread michael rice
Thanks for the tip, Ozgur. It worked for me. Is this what you had in mind, Ryan?

Michael

==

import Control.Monad.State.Lazy
import Control.Monad
import System.Random

type GeneratorState = State StdGen
data Craps a = Roll a | Win a | Lose a deriving (Show)

genRandomR :: Random a = (a,a) - GeneratorState a
genRandomR = state . randomR

rollDie :: GeneratorState Int
rollDie = genRandomR (1,6)

roll2Dice :: GeneratorState Int
roll2Dice = liftM2 (+) rollDie rollDie

f :: Craps [Int] - GeneratorState (Craps [Int])
f (Roll []) = do g0 - get
 let (throw1,g1) = runState roll2Dice g0
 put g1
 case throw1 of
    2 - return (Lose [throw1])
    3 - return (Lose [throw1])
    7 - return (Win [throw1])
    11 - return (Win [throw1])
    _ - do g1 - get
    let (throw2,g2) = runState roll2Dice g1
    put g2
    if throw2 == throw1
  then do return (Win [throw1,throw2])
  else
    if throw2 == 7
  then do return (Lose [throw1,throw2])
  else do f (Roll [throw1,throw2])
f (Roll z@(throw1:throws)) = do g0 - get
    let (throw,g1) = runState roll2Dice g0
    put g1
    if throw == throw1
  then do return (Win (z ++ [throw]))
  else
    if throw == 7
  then do return (Lose (z ++ [throw]))
  else do f (Roll (z ++ [throw]))



--- On Wed, 12/22/10, Ozgur Akgun ozgurak...@gmail.com wrote:

From: Ozgur Akgun ozgurak...@gmail.com
Subject: Re: [Haskell-cafe] Why is Haskell flagging this?
To: Ryan Ingram ryani.s...@gmail.com
Cc: haskell-cafe@haskell.org, Daniel Fischer 
daniel.is.fisc...@googlemail.com
Date: Wednesday, December 22, 2010, 7:37 PM

see 
also: http://hackage.haskell.org/packages/archive/mtl/latest/doc/html/Control-Monad-State-Lazy.html#v:state


On 22 December 2010 20:02, Ryan Ingram ryani.s...@gmail.com wrote:

Interesting.  In that case,



state f = StateT $ \s - Identity (f s)



allows state to replace State in that code.
Ozgur

-Inline Attachment Follows-

___
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] UTF-8 in Haskell.

2010-12-22 Thread Magicloud Magiclouds
Hi,
  Recently, I am reading ssh hackage
(http://hackage.haskell.org/package/ssh). When at the part of deal
with string, I got confused. I am not sure if this is a bug for the
hackage, or I am just misunderstanding.
  An ascii char takes a Word8. So this works (LBS stands for
Data.ByteString.Lazy):
toLBS :: String - LBS.ByteString
toLBS = LBS.pack . map (fromIntegral . fromEnum)
  But a UTF-8 char takes a Int (Word32). Then I think the above code
would break the data, right?
  If so, OK, then I think I could make a packInt which turns an Int
into 4 Word8 first. Thus under all situation (ascii, UTF-8, or even
UTF-32), my program always send 4 bytes through the network. Is that
OK?
-- 
竹密岂妨流水过
山高哪阻野云飞

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


[Haskell-cafe] ANN: cabal-dev 0.7.3.1 -- now with ghci!

2010-12-22 Thread Rogan Creswick
Cabal-dev is now capable of launching ghci with the project's package
database and local modules (if the package under development exposes a
library).  For example:

# First, invoke cabal-dev install the package to populate the
# package database:
$ cabal-dev install

snip

$ cabal-dev ghci
GHCi, version 6.12.3: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Prelude

The ghci shell should have access to all the libraries your
application/library is using, as well as any modules that your library
exposes.

Note that this is not quite as natural as your traditional ghci shell,
namely: Source modifications are not visible without exiting,
re-issuing `cabal-dev install` *and* `cabal-dev ghci`.  This will
eventually get better, but that's where things are right now.  The
reason for this is that `cabal-dev ghci` just issues ghci with the
cabal-dev package database (and excluding the user package db, to best
reflect what cabal-dev does when it causes compilation).

Cabal-dev is available on hackage and github:
 - http://hackage.haskell.org/package/cabal-dev
 - https://github.com/creswick/cabal-dev

There is a short write-up with a (slightly) longer example here:
 -
http://blog.ciscavate.org/2010/12/cabal-dev-sandboxing-your-haskell-development-and-now-with-ghci.html

--Rogan



smime.p7s
Description: S/MIME Cryptographic Signature
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] UTF-8 in Haskell.

2010-12-22 Thread Mark Lentczner

On Dec 22, 2010, at 9:29 PM, Magicloud Magiclouds wrote:
 Thus under all situation (ascii, UTF-8, or even
 UTF-32), my program always send 4 bytes through the network. Is that
 OK?

Generally, no.

Haskell strings are sequences of Unicode characters. Each character has an 
integral code point value, from 0 to 0x10, but technically, the code point 
itself is just a number, not a pattern of bits to be exchanged. That is an 
encoding.

In any protocol you need know the encoding before you exchange characters as 
bytes or words. In some protocols it is implicit, in others explicit in header 
or meta data, and in yet others (IRC comes to mind) it is undefined (which 
makes problems for the user).

The UTF-8 encoding uses a variable number of bytes to represent each character, 
depending on the code point, not Word32 as you suggested.

Converting from Haskell's String to various encodings can be done with either 
the text package or utf8-string package.

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


Re: [Haskell-cafe] UTF-8 in Haskell.

2010-12-22 Thread Magicloud Magiclouds
On Thu, Dec 23, 2010 at 2:01 PM, Mark Lentczner ma...@glyphic.com wrote:

 On Dec 22, 2010, at 9:29 PM, Magicloud Magiclouds wrote:
 Thus under all situation (ascii, UTF-8, or even
 UTF-32), my program always send 4 bytes through the network. Is that
 OK?

 Generally, no.

 Haskell strings are sequences of Unicode characters. Each character has an 
 integral code point value, from 0 to 0x10, but technically, the code 
 point itself is just a number, not a pattern of bits to be exchanged. That is 
 an encoding.

 In any protocol you need know the encoding before you exchange characters as 
 bytes or words. In some protocols it is implicit, in others explicit in 
 header or meta data, and in yet others (IRC comes to mind) it is undefined 
 (which makes problems for the user).

 The UTF-8 encoding uses a variable number of bytes to represent each 
 character, depending on the code point, not Word32 as you suggested.

 Converting from Haskell's String to various encodings can be done with either 
 the text package or utf8-string package.

                - Mark

I see. I just realize that, in this case (ssh), I could use CString to
avoid all problems about encoding.

-- 
竹密岂妨流水过
山高哪阻野云飞

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