[Haskell-cafe] Re: StateT IO Action on `onKeyPress`

2009-05-05 Thread Andy Stewart
Ryan Ingram ryani.s...@gmail.com writes:

 Something like this:

 -- Replaces runStateT for callbacks that might affect the state
 invert :: IORef s - StateT s IO a - IO a
 invert r m = do
 s - readIORef r
 (a, s') - runStateT m s
 writeIORef r s'
 return a

 -- Replaces liftIO when the action called might use invert
 revert :: IORef s - IO a - StateT s IO a
 revert r m = do
 s - get
 writeIORef r s
 a - liftIO m
 s' - readIORef r
 put s'
 return a

 Then  you use ... `onKeyPress` (\event - invert windowListRef (...))

 I'm not sure where in your code revert is required; I don't know when
 WindowListT might call back into IO.  If you want to be extra safe,
 make the IORef be a Maybe WindowList and make sure it's Nothing
 except between 'revert' and 'invert'.
Result is ReaderT is cleaner and simpler.

Thanks for your help!

  -- Andy


   -- ryan

 On Mon, May 4, 2009 at 1:02 AM, Andy Stewart lazycat.mana...@gmail.com 
 wrote:
 Hi Ryan,

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

 Hi Andy.

 The GTK bindings use IO for their callbacks, not any custom monad like
 your WindowListT.

 I suggest, instead of StateT s IO a, you use ReaderT (IORef s) IO a:

 putR :: s - ReaderT (IORef s) IO ()
 putR s = do
     r - ask
     liftIO $ writeIORef r s

 getR :: ReaderT (IORef s) IO s
 getR = ask = liftIO . readIORef

 Otherwise, there are techniques to use an IORef to hold onto the state
 while calling into IO (which might make callbacks), and then read it
 back out and put it in the state while running your action.  But it's
 simpler to just switch to ReaderT
 I'm curious another techniques that use IORef hold on state.

 Can you implement a simple example that make my code pass `onKeyPress`?

 Thanks!

  -- Andy


   -- ryan

 On Sun, May 3, 2009 at 8:27 AM, Andy Stewart lazycat.mana...@gmail.com 
 wrote:
 Hi all,

 I have a function named `keymapTest` need moand state WindowListT, and
 WindowListT is `type WindowListT = StateT WindowList IO`.

 when i add (\event - keymapTest winList event  return False) after
 `onKeyPress` for handle key press event, i got GHC error:

 Manatee.hs:57:58:
    Couldn't match expected type `IO a'
           against inferred type `WindowListT Bool'
    In the first argument of `()', namely `keymapTest winList event'
    In the expression: keymapTest winList event  return False
    In the second argument of `onKeyPress', namely
        `(\ event - keymapTest winList event  return False)'

 So function `onKeyPress` just accept *one* IO-action?
 Have a way to fix above problem?

 Any help?

 Thanks!

  -- Andy

 Below is source code of Manatee.hs file.

 -- Manatee.hs start   
 --
 module Main where

 import Text.Printf
 import Data.Monoid
 import Data.List
 import Data.Maybe
 import Control.Monad
 import Control.Monad.State
 import Control.Applicative

 import Data.IORef

 import Graphics.UI.Gtk hiding (Window, windowNew, get)
 import Graphics.UI.Gtk.SourceView
 import Graphics.UI.Gtk.Abstract.Widget

 import Manatee.Event
 import Manatee.Buffer
 import Manatee.WindowList
 import Manatee.Pane
 import Manatee.Statusbar
 import Manatee.Utils
 import Manatee.Window

 import qualified Data.Set as Set
 import qualified Graphics.UI.Gtk.Windows.Window as W
 import qualified Graphics.UI.Gtk.Gdk.Events as E

 main :: IO ()
 main = do
  -- Init.
  initGUI

  -- Root frame.
  rootFrame - W.windowNew
  rootFrame `onDestroy` mainQuit  -- quit main loop when root frame close

  -- Root frame status.
  windowFullscreen rootFrame   -- fullscreen

  -- Windows list.
  let windowsList = WindowList 0 Set.empty

  evalStateT (do
               -- Window 1
               window1 - windowNewWithBuffer DTop test
               liftIO $ containerAdd rootFrame $ windowPaned window1

               (window2, window3) - windowSplitVertically window1

               (window4, window5) - windowSplitHorizontally window3

               winList - windowListGetList
               liftIO $ rootFrame `onKeyPress` (\event - keymapTest 
 winList event  return
 False)

               -- Handle window content synchronous.
               windowHandleSynchronous
               ) windowsList

  -- Loop
  widgetShowAll rootFrame       -- display all widget
  mainGUI

 keymapTest :: [Window] - E.Event - WindowListT Bool
 keymapTest winList event = do
  window - liftIO $ windowFindFocus winList
  case window of
    Just x - handleKeyPress x event
    Nothing - return False

 handleKeyPress :: Window - E.Event - WindowListT Bool
 handleKeyPress window ev = do
  liftIO $
         case eventTransform ev of
           Nothing - return False
           Just e - do
             let display = statusbarOutputSubitemSetText $ paneStatusbar $ 
 windowPane $ window
                 eventName = eventGetName e
             case eventName of
                -- Window commands.
                M-t - display windowSplitVertically
                -- 

Re: [Haskell-cafe] applicative challenge

2009-05-05 Thread david48
On Mon, May 4, 2009 at 11:49 PM, Conor McBride
co...@strictlypositive.org wrote:

 Remember folks: Missiles need miffy!

Quote of the week !
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] applicative challenge

2009-05-05 Thread Thomas Davie


On 4 May 2009, at 23:15, Thomas Hartman wrote:


{-# LANGUAGE NoMonomorphismRestriction #-}
import Data.List
import Control.Monad
import Control.Applicative

-- Can the function below be tweaked to quit on blank input,
provisioned in the applicative style?
-- which function(s) needs to be rewritten to make it so?
-- Can you tell/guess which function(s) is the problem just by looking
at the code below?
-- If so, can you explain what the strategy for doing so is?
notQuiteRight = takeWhile (not . blank) $ ( sequence . repeat $  
echo )


echo = do
 l - getLine
 putStrLn l
 return l


-- this seems to work... is there a way to make it work Applicatively,
with lifted takeWhile?
seemsToWork = sequenceWhile_ (not . blank) (repeat echo)

sequenceWhile_ p [] = return ()
sequenceWhile_ p (mx:mxs) = do
 x - mx
 if p x
   then do sequenceWhile_ p mxs
   else return ()


Conor's already give you a comprehensive explanation of why  
Applicative can't be used to do this, but that doesn't mean you can't  
use applicative style!


How about...

echo = unlines . takeWhile (not . blank) . lines

seemsToWork = interact echo

Bob

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


Re: [Haskell-cafe] A brief note on n_k patterns and Hackage

2009-05-05 Thread Magnus Therning
On Tue, May 5, 2009 at 1:04 AM, Richard O'Keefe o...@cs.otago.ac.nz wrote:
 I never really understood why it was thought to be relevant,
 but I was challenged to show that n+k patterns occurred in
 Hackage.

Why is it relevant?

/M

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


[Haskell-cafe] setResourceLimit

2009-05-05 Thread brian
I have a long-lived multithreaded server process that needs to execute
programs and interact with them via Handles. The programs could
misbehave, like loop or hang, so I need to limit the real and CPU time
they can take.

I guess System.Posix.Resource.setResourceLimit sets limits on the
current process, so I can't use it in the server process. Is it a good
approach to write some utility program for the server to call that does
setResourceLimit and executes the programs that could misbehave?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] How to understand the fmap here ?

2009-05-05 Thread z_axis
The following code snippets is from xmonad:
-- Given a window, find the screen it is located on, and compute
-- the geometry of that window wrt. that screen.
floatLocation :: Window - X (ScreenId, W.RationalRect)
--...
rr - snd `fmap` floatLocation w

Prelude :i fmap
class Functor f where fmap :: (a - b) - f a - f b

It seems it is different from the definition of fmap ?
sincerely!

2009-05-05 



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


Re: [Haskell-cafe] How to understand the fmap here ?

2009-05-05 Thread Thomas Davie


On 5 May 2009, at 11:27, z_axis wrote:


The following code snippets is from xmonad:
-- Given a window, find the screen it is located on, and compute
-- the geometry of that window wrt. that screen.
floatLocation :: Window - X (ScreenId, W.RationalRect)
--...
rr - snd `fmap` floatLocation w

Prelude :i fmap
class Functor f where fmap :: (a - b) - f a - f b

It seems it is different from the definition of fmap ?
sincerely!


As the type signature of fmap explains, it transforms a function.   
Specifically, it starts with a function (a - b), and it transforms it  
to accept an 'a' inside a functor instead of just an a, and return a  
'b' inside the same functor instead of just a b.  In other words, fmap  
applies functions inside containers.


We can see from floatLocation that it returns a pair inside a  
container - specifically, an X container.  Fmap takes snd, and  
transforms it to work on values inside the X.


So, snd has type (a,b) - b, thus fmap snd has type f (a,b) - f b.   
In this case, the type it's being applied to is X (ScreenId,  
W.RationalRect), so f unifies with X, a with ScreenID and b with  
W.RationalRect.  Making snd `fmap` floatLocation w hav the type X  
W.RationalRect.


Finally, the bind into rr there takes it out of the X monad all  
together, getting you a W.RationalRect.


You may want to read this article which explains some of Haskell's  
abstraciton mechanisms:


http://noordering.wordpress.com/2009/03/31/how-you-shouldnt-use-monad/

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


Re: [Haskell-cafe] How to understand the fmap here ?

2009-05-05 Thread minh thu
2009/5/5 z_axis z_a...@163.com:
 The following code snippets is from xmonad:
 -- Given a window, find the screen it is located on, and compute
 -- the geometry of that window wrt. that screen.
 floatLocation :: Window - X (ScreenId, W.RationalRect)
 --...
 rr - snd `fmap` floatLocation w

 Prelude :i fmap
 class Functor f where fmap :: (a - b) - f a - f b

 It seems it is different from the definition of fmap ?
 sincerely!

X is a Functor (and a Monad).

floatLocation w :: X (ScreenId, W.RationalRect) -- i.e. f is X and a
is (ScreenId, W.RationalRect)
snd :: (ScreenId, W.RationalRect) - W.RationalRect
fmap :: (same as snd) - X (ScreenId, W.RationalRect) - X W.RationalRect

Makes sense ?

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


Re: [Haskell-cafe] How to understand the fmap here ?

2009-05-05 Thread Bulat Ziganshin
Hello z_axis,

Tuesday, May 5, 2009, 1:27:16 PM, you wrote:

 floatLocation :: Window - X (ScreenId, W.RationalRect)

 rr - snd `fmap` floatLocation w

 class Functor f where fmap :: (a - b) - f a - f b

looks ok. X===f, fmap executes

floatLocation w :: X (ScreenId, W.RationalRect)  ===  f a

and then applies

snd :: (ScreenId, W.RationalRect) - W.RationalRect  ===  a-b

to result, so that entire (snd `fmap` floatLocation w) has type

X W.RationalRect  ===  f b



-- 
Best regards,
 Bulatmailto:bulat.zigans...@gmail.com

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


Re: [Haskell-cafe] Re: Is Haskell a Good Choice for Web Applications? (ANN: Vocabulink)

2009-05-05 Thread Daniel Carrera

Chris Forno (jekor) wrote:

The idea is that I spent years studying different languages, generally
with a textbook. The textbooks tend to focus on teaching rules and
grammar, with a little bit of vocabulary and dialog each chapter. I
think the focus should be reversed.


I think it largely depends on the learner. Some people find vocabulary 
easier, or more interesting, others not. I have a hard time learning a 
lot of isolated facts (e.g. vocabulary), but I find it easier and more 
enjoyable to learn a rule that I can apply many times. But I know people 
who are the exact opposite. I wouldn't want to make an absolute rule.


I generally like rules that will save me a lot of memorization. I hate 
rules that force me to memorize a lot. I am not good at memorization.




I consider myself to be a highly logically-oriented
(audio-digital?) learning type, as I expect many programmers are.
However, I still don't remember most grammar lessons. The only way I
successfully became fluent in a language (Esperanto) was through
immersion, and that wouldn't have been possible without a decent
vocabulary to start with.


I totally understand, and I agree. And with only a few exceptions, I 
would say that vocabulary is more useful than grammar (even if I find 
the former harder to learn).


That said, I cause Esperanto as a good example of a language with rules 
that make learning easier. In Esperanto, the ending of a word tells you 
if the word is a noun, a verb, an adjective, a subject, an object, etc. 
Knowing these rules makes it much easier for you to learn Esperanto. 
When I learn a language, I like learning rules that will make language 
learning easier.




That being said, Esperanto, and even Japanese sentence structure perhaps
is not as different as an agglutinative language like German. I'll need
to study it more to find out.


In the specific case of German, word order is a lot more important than 
any other language I know. You can get everything else about grammar 
wrong, but as long as you put the words in the right place people will 
probably understand you. But if you get everything else right, and put 
the words in the wrong place, you won't be understood.





Absolutely. I'm not trying to claim that you only need 1,000 words to
become fluent, like some courses claim.


Ok. I probably misunderstood something.



The idea is that once you can begin to read with a dictionary by your
side you'll begin learning much faster because you can focus on reading
what *you* are interested in rather than some contrived dialog from a
textbook.


In my case, the things I'm interested in are too technical :-(  I've had 
a hard time finding things that are interesting and are simple enough 
for me to read in German. But I'll get better.




So far I've been focusing on Japanese. I only have 15 or so stories
currently. They take a bit of time to create ;) For now, the navigation
is basically to click the Latest Links link in the header bar or in
the Latest Links box.


Ok.

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


Re: [Haskell-cafe] applicative challenge

2009-05-05 Thread Thomas Hartman
That's slick, but is there some way to use interact twice in the same program?

t10 =
  let f = unlines . takeWhile (not . blank) . lines
  in  do putStrLn first time
 interact f
 putStrLn second time
 interact f

this results in *** Exception: stdin: hGetContents: illegal
operation (handle is closed) -}

I also tried

t15 =
  let grabby = unlines . takeWhile (not . blank) . lines
  top = (first time:  ++) . grabby . (second time:  ++) . grabby
  in  interact top


but that didn't work either:

thart...@ubuntu:~/haskell-learning/lazy-n-strictrunghc sequencing.hs
a
first time: second time: a
b
b

If someone can explain the subtleties of using interact when you run
out of stdio here, it would be nice to incorporate this into

http://www.haskell.org/haskellwiki/Haskell_IO_for_Imperative_Programmers#IO

where it talks about how using interact is the easy way to approach
these types of problems. Not *that* easy though, as this scenario
suggests.



2009/5/5 Thomas Davie tom.da...@gmail.com:

 On 4 May 2009, at 23:15, Thomas Hartman wrote:

 {-# LANGUAGE NoMonomorphismRestriction #-}
 import Data.List
 import Control.Monad
 import Control.Applicative

 -- Can the function below be tweaked to quit on blank input,
 provisioned in the applicative style?
 -- which function(s) needs to be rewritten to make it so?
 -- Can you tell/guess which function(s) is the problem just by looking
 at the code below?
 -- If so, can you explain what the strategy for doing so is?
 notQuiteRight = takeWhile (not . blank) $ ( sequence . repeat $ echo )

 echo = do
         l - getLine
         putStrLn l
         return l


 -- this seems to work... is there a way to make it work Applicatively,
 with lifted takeWhile?
 seemsToWork = sequenceWhile_ (not . blank) (repeat echo)

 sequenceWhile_ p [] = return ()
 sequenceWhile_ p (mx:mxs) = do
  x - mx
  if p x
   then do sequenceWhile_ p mxs
   else return ()

 Conor's already give you a comprehensive explanation of why Applicative
 can't be used to do this, but that doesn't mean you can't use applicative
 style!

 How about...

 echo = unlines . takeWhile (not . blank) . lines

 seemsToWork = interact echo

 Bob


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


Re: [Haskell-cafe] applicative challenge

2009-05-05 Thread Ketil Malde
Thomas Hartman tphya...@gmail.com writes:

 That's slick, but is there some way to use interact twice in the same program?

No :-)

 t10 =
   let f = unlines . takeWhile (not . blank) . lines
   in  do putStrLn first time
  interact f
  putStrLn second time
  interact f

 this results in *** Exception: stdin: hGetContents: illegal
 operation (handle is closed) -}

Yes. Interacting uses hGetContents, and hGetContents semi-closes (or
fully-closes) the handle.  If you do it from GHCi, you only get to run
your program once.

 I also tried

 t15 =
   let grabby = unlines . takeWhile (not . blank) . lines
   top = (first time:  ++) . grabby . (second time:  ++) . grabby
   in  interact top

 but that didn't work either:
 thart...@ubuntu:~/haskell-learning/lazy-n-strictrunghc sequencing.hs
 a
 first time: second time: a
 b
 b

Well - the input to the leftmost grabby is second time prepended to
the input from the first, and then you prepend first time - so this
makes sense. 

Something like this, perhaps:

interact (\s - let (first,second) = span (not . null) (lines s) 
in unlines (first:first++second:takeWhile (not.null) 
second))

 If someone can explain the subtleties of using interact when you run
 out of stdio here, it would be nice to incorporate this into

hGetContents - there can only be one.

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] applicative challenge

2009-05-05 Thread Thomas Davie

I also tried

t15 =
 let grabby = unlines . takeWhile (not . blank) . lines
 top = (first time:  ++) . grabby . (second time:  ++) .  
grabby

 in  interact top


but that didn't work either:

thart...@ubuntu:~/haskell-learning/lazy-n-strictrunghc sequencing.hs
a
first time: second time: a
b
b

If someone can explain the subtleties of using interact when you run
out of stdio here, it would be nice to incorporate this into


Essentially, what's happening here is that interact consumes *all* of  
standard input, and runs your function on it.  This means that as  
you've realised here, your function must do *all* of the processing of  
input in one go – but this is good!  This means our IO is restricted  
to one tiny little corner of the program, and we get to write pure  
Haskell everywhere else :)


What's going on with your top function on the other hand is that (.)  
is not `after` in the sense you're thinking.


If you want one grabby to consume some of the input, but not all of it  
you'd need to return a pair containing the output, and the unconsumed  
input.



where it talks about how using interact is the easy way to approach
these types of problems. Not *that* easy though, as this scenario
suggests.


The key here is that it's more composable than using IO – IO can  
change all kinds of wierd state, and result in two functions doing  
totally different things depending on when they're called.  This means  
you can't reliably stick bits of IO code together.  With pure  
functional code though, referential transparency guarentees that you  
can.


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


Re: [Haskell-cafe] applicative challenge

2009-05-05 Thread Thomas Hartman
seems to be the same behavior whether in ghci or compiled with ghc.

2009/5/5 Ketil Malde ke...@malde.org:
 Thomas Hartman tphya...@gmail.com writes:

 That's slick, but is there some way to use interact twice in the same 
 program?

 No :-)

 t10 =
   let f = unlines . takeWhile (not . blank) . lines
   in  do putStrLn first time
          interact f
          putStrLn second time
          interact f

 this results in *** Exception: stdin: hGetContents: illegal
 operation (handle is closed) -}

 Yes. Interacting uses hGetContents, and hGetContents semi-closes (or
 fully-closes) the handle.  If you do it from GHCi, you only get to run
 your program once.

 I also tried

 t15 =
   let grabby = unlines . takeWhile (not . blank) . lines
       top = (first time:  ++) . grabby . (second time:  ++) . grabby
   in  interact top

 but that didn't work either:
 thart...@ubuntu:~/haskell-learning/lazy-n-strictrunghc sequencing.hs
 a
 first time: second time: a
 b
 b

 Well - the input to the leftmost grabby is second time prepended to
 the input from the first, and then you prepend first time - so this
 makes sense.

 Something like this, perhaps:

 interact (\s - let (first,second) = span (not . null) (lines s)
                in unlines (first:first++second:takeWhile (not.null) 
 second))

 If someone can explain the subtleties of using interact when you run
 out of stdio here, it would be nice to incorporate this into

 hGetContents - there can only be one.

 -k
 --
 If I haven't seen further, it is by standing in the footprints of giants

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


[Haskell-cafe] Parsec - Custom Fail

2009-05-05 Thread mwinter
Hi,

I am using parsec to parse a small programming language. The language is typed 
and
I need to do some type checking, too. I have decided to do the parsing and type 
checking
simultaneously in the my parsec parser. This approach avoids to keep source 
code positions
in the data type in order to produce suitable error messages during type 
checking. Anyhow,
because type errors are usually detected after parsing some code I need produce 
error
messages with an earlier source position. Unfortunately, there is no function 
that produces 
an error taking a position as parameter. 

I tried the following:

myFail :: SourcePos - String - GenParser tok st a
myFail pos msg = setPosition pos  fail msg

This is already a workaround because I am modifying the position in the parser 
just to
produce an error message. But even worse, it does not work. If I use this 
function as in:

test :: Either ParseError ()
test = runParser (char '('  myFail (newPos  100 100) Test) ()  (

the position of the error is still the original position (line 1, column 2). As 
far as I can tell
setPosition does not take effect until another symbol is read. This could be 
achieved by
simply using anyToken if we are not at the end of the input (as in the example 
above). I
came up with the following:

myFail :: SourcePos - String - GenParser Char st a
myFail pos msg = do {
 State toks _ st - getParserState;
 setParserState $ State ('d':toks) pos st;
 anyToken;
 fail msg
  }

This code works but it is not nice at all. The function myFail is not longer 
polymorphic in
the type of tokens since we need an element of this data type in order to add 
it temporarily
to the input ('d' above).

My guess is that one has to enforce strictness at some point in order to work 
with the first
approach, but I was not successful. Any ideas?

Thanks,
Michael


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


Re: [Haskell-cafe] Parsec - Custom Fail

2009-05-05 Thread Neil Brown

Hi,

When we needed to do something similar with Parsec, we chose to pack the 
relevant source position into the error string (you can just use 
Show/Read, plus a special sequence of characters to indicate where the 
position ends and the real error starts).  We then unpack it outside 
runParser before issuing the error to the user.  If there's no packed 
position found, we just use the Parsec position.


Thanks,

Neil.


mwin...@brocku.ca wrote:

Hi,

I am using parsec to parse a small programming language. The language is typed 
and
I need to do some type checking, too. I have decided to do the parsing and type 
checking
simultaneously in the my parsec parser. This approach avoids to keep source 
code positions
in the data type in order to produce suitable error messages during type 
checking. Anyhow,
because type errors are usually detected after parsing some code I need produce 
error
messages with an earlier source position. Unfortunately, there is no function that produces 
an error taking a position as parameter. 


I tried the following:

myFail :: SourcePos - String - GenParser tok st a
myFail pos msg = setPosition pos  fail msg

This is already a workaround because I am modifying the position in the parser 
just to
produce an error message. But even worse, it does not work. If I use this 
function as in:

test :: Either ParseError ()
test = runParser (char '('  myFail (newPos  100 100) Test) ()  (

the position of the error is still the original position (line 1, column 2). As 
far as I can tell
setPosition does not take effect until another symbol is read. This could be 
achieved by
simply using anyToken if we are not at the end of the input (as in the example 
above). I
came up with the following:

myFail :: SourcePos - String - GenParser Char st a
myFail pos msg = do {
 State toks _ st - getParserState;
 setParserState $ State ('d':toks) pos st;
 anyToken;
 fail msg
  }

This code works but it is not nice at all. The function myFail is not longer 
polymorphic in
the type of tokens since we need an element of this data type in order to add 
it temporarily
to the input ('d' above).

My guess is that one has to enforce strictness at some point in order to work 
with the first
approach, but I was not successful. Any ideas?

Thanks,
Michael


___
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] Parsec - Custom Fail

2009-05-05 Thread Martijn van Steenbergen

mwin...@brocku.ca wrote:

Hi,

I am using parsec to parse a small programming language. The language is typed 
and
I need to do some type checking, too. I have decided to do the parsing and type 
checking
simultaneously in the my parsec parser. This approach avoids to keep source 
code positions
in the data type in order to produce suitable error messages during type 
checking. Anyhow,
because type errors are usually detected after parsing some code I need produce 
error
messages with an earlier source position. Unfortunately, there is no function that produces 
an error taking a position as parameter. 


If you already know what position you want to report the error at, then 
why bother calling setPosition to let parsec know? Just do:


 fail (show pos ++ :  ++ msg)

Parsec will then result in a ParseError with its own ideas of location, 
but you can ignore that.


HTH,

Martijn.

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


[Haskell-cafe] List comprehension

2009-05-05 Thread applebiz89

Hi, I think I need to use a list comprehension for this function but Im not
good with list comprehension. this is what I have so at the moment?

filmsInGivenYear :: Int - [Film] - [String]
filmsInGivenYear filmYear ?= [ title | year - (Film title director year
fans) , year == filmYear] (this code wont compile - error given '?Syntax
error in expression (unexpected `;', possibly due to bad layout)')

Is there an alternative solution instead of comprehension? I want the
function to be given a release date and then return all films with that
date.

Thanks
-- 
View this message in context: 
http://www.nabble.com/List-comprehension-tp23389686p23389686.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] List comprehension

2009-05-05 Thread Bulat Ziganshin
Hello applebiz89,

Tuesday, May 5, 2009, 7:20:35 PM, you wrote:

 filmsInGivenYear :: Int - [Film] - [String]
 filmsInGivenYear filmYear ?= [ title | year - (Film title director year
 fans) , year == filmYear] (this code wont compile - error given '?Syntax
 error in expression (unexpected `;', possibly due to bad layout)')

you forget films list variable:

filmsInGivenYear filmYear films =
  [ title | (Film title director year fans) - films, year == filmYear]


-- 
Best regards,
 Bulatmailto:bulat.zigans...@gmail.com

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


Re: [Haskell-cafe] List comprehension

2009-05-05 Thread minh thu
2009/5/5 applebiz89 applebi...@hotmail.com:

 Hi, I think I need to use a list comprehension for this function but Im not
 good with list comprehension. this is what I have so at the moment?

 filmsInGivenYear :: Int - [Film] - [String]
 filmsInGivenYear filmYear ?= [ title | year - (Film title director year
 fans) , year == filmYear] (this code wont compile - error given '?Syntax
 error in expression (unexpected `;', possibly due to bad layout)')

 Is there an alternative solution instead of comprehension? I want the
 function to be given a release date and then return all films with that
 date.

Hi,

I suggest you start by some simple examples, then move to your goal.
For instance you can try to write a function which takes in input a list of
Int and outputs a list of those Int that are odd.

f [1,2,3,4,5] = [1,3,5]

You can generalise this function to accept a predicate.

g even [1,2,3,4,5] = [2,4]

Returning back to your problem, can you write a function that takes
a Film and returns its release date ? Then you can write a function
which test if that date match a given one.

Then, finally, you can write a function which get a list of Film and outputs
only those satisfying your desire.

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


Re: [Haskell-cafe] List comprehension

2009-05-05 Thread Tillmann Rendel

Hi,

applebiz89 wrote:
 Hi, I think I need to use a list comprehension

There is no need to use list comprehensions, there is always a way to 
express the same thing without them. In fact, list comprehensions are 
defined as syntactic shorthands for this other way.



filmsInGivenYear :: Int - [Film] - [String]
filmsInGivenYear filmYear ?= [ title | year - (Film title director year
fans) , year == filmYear] 


Let's look at the type of your function. You have two arguments of types 
Int and [Film], so your definition should have two argument names:


  filmsInGivenYear filmYear films
= ...

Now, we want to look at each of the films

  filmsInGivenYear filmYear films
= [ ... | film - films ... ]

The part film - films means: Look at each element of films in turn, 
and name the current one film.


But we actually want to look inside the film (we want to check the year).

  filmsInGivenYear filmYear films
= [ ... | Film title director year fans - films ...]

This means to look at each of the films in turn, and match the current 
film against the pattern (Film title director year fans). So if the 
current film has been created by a call like (Film ...), we will get the 
various data fields in the variables title, directory, year and fans.


Now we want to check that the year is correct.

  filmsInGivenYear filmYear films
= [ ... | Film title director year fans - films, filmYear == year]

The part (filmYear == year) means that we are only interested in such 
films where year is filmYear.


Finally, we want to return the name of the remaining films.

  filmsInGivenYear filmYear films
= [title | Film title director year fans - films, filmYear == year]

Hope that helps,
  Tillmann

PS. I'm not a native speaker, but shouldn't it be movies and not films?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Parsec - Custom Fail

2009-05-05 Thread mwinter
Thanks, but I want a nice solution not another, even more complicated, 
workaround.

On 5 May 2009 at 17:10, Martijn van Steenbergen wrote:

 mwin...@brocku.ca wrote:
  Hi,
  
  I am using parsec to parse a small programming language. The language is 
  typed and
  I need to do some type checking, too. I have decided to do the parsing and 
  type checking
  simultaneously in the my parsec parser. This approach avoids to keep source 
  code positions
  in the data type in order to produce suitable error messages during type 
  checking. Anyhow,
  because type errors are usually detected after parsing some code I need 
  produce error
  messages with an earlier source position. Unfortunately, there is no 
  function that produces 
  an error taking a position as parameter. 
 
 If you already know what position you want to report the error at, then 
 why bother calling setPosition to let parsec know? Just do:
 
   fail (show pos ++ :  ++ msg)
 
 Parsec will then result in a ParseError with its own ideas of location, 
 but you can ignore that.
 
 HTH,
 
 Martijn.


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


Re: [Haskell-cafe] List comprehension

2009-05-05 Thread Brent Yorgey
On Tue, May 05, 2009 at 05:36:12PM +0200, Tillmann Rendel wrote:

 PS. I'm not a native speaker, but shouldn't it be movies and not films?

Both are correct. =)

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


Re: [Haskell-cafe] A brief note on n_k patterns and Hackage

2009-05-05 Thread Jason Dagit
On Tue, May 5, 2009 at 1:30 AM, Magnus Therning mag...@therning.org wrote:
 On Tue, May 5, 2009 at 1:04 AM, Richard O'Keefe o...@cs.otago.ac.nz wrote:
 I never really understood why it was thought to be relevant,
 but I was challenged to show that n+k patterns occurred in
 Hackage.

 Why is it relevant?

Showing that they occur was not relevant.  Showing the number of
occurrences relative to the number of packages, function definitions,
and other features was relevant (in my opinion):
http://www.mail-archive.com/haskell-cafe@haskell.org/msg58320.html

But, I phrased the challenge poorly and this is what we get :)  I was
just curious if it's a feature worth holding on it (eg., it gets a lot
of good use).  Sadly, just me commenting here about that goal will
probably rekindle the thread we would all like to avoid...  My
sincerest apologizes if that happens.

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


Re: [Haskell-cafe] A brief note on n_k patterns and Hackage

2009-05-05 Thread j3h
On Mon, May 4, 2009 at 5:23 PM, John Van Enk vane...@gmail.com wrote:
 Which package?

In 1251 packages, I found 20 source files out of 15144 source files
that use (n+k) patterns:

queuelike-1.0.9/Data/Queue/Stack.hs
queuelike-1.0.9/Data/Queue/TrieQueue.hs
hinze-streams-1.0/Data/Stream/Hinze/Stream.hs
compression-0.1/Codec/Compression/Utils.hs
bytestring-0.9.1.4/tests/lazybuildcons.hs
bytestring-0.9.1.4/tests/lazybuild.hs
liboleg-0.1.1/Language/TypeLC.hs
pqueue-mtl-1.0.7/Data/Queue/Stack.hs
pqueue-mtl-1.0.7/Data/Queue/Queue.hs
IOSpec-0.2/examples/Echo.hs
pxsl-tools-1.0.1/src/PxsltFormat.hs
pdf2line-0.0.1/pdf2line.hs
stream-fusion-0.1.2.1/tests/Test/SmallCheck/Partial.hs
queue-0.1.1.3/src/Data/Queue/Instances/STM.hs
frag-1.1.2/src/AFRP.hs
th-fold-0.0.0.1/src/Language/Haskell/TH/Fold.hs
tetris-0.27178/Util.hs
random-fu-0.0.0.2/src/Data/Random/Distribution/Binomial.hs
random-fu-0.0.0.2/src/Data/Random/Source/PureMT.hs

The method that I used to extract them may have missed some files
(e.g. anything that is Haskell source but needs to be preprocessed),
but I just wanted to save people the trouble of finding them
themselves ;)

j3h

--
For the curious, those who wish to search other sources, or those who
wish to improve on my results, I found these by I downloaded the full
Hackage tarball, unpacked it and ran:

find ./ -type f \( -name \*.hs -o \*.lhs \) | xargs npk

where npk is the following program:

 import System.Environment ( getArgs )
 import Control.Monad ( when )
 import Data.Generics ( cast, GenericQ, gcount )
 import Language.Haskell.Exts ( Module, ParseResult(..), Pat(..), parseFile )

 isNPlusK :: GenericQ Bool
 isNPlusK x = case cast x of
Just (PNPlusK _ _) - True
_ - False

 hasNPlusK :: Module - Bool
 hasNPlusK = ( 0) . gcount isNPlusK

 printIfNPlusK :: FilePath - IO ()
 printIfNPlusK fn = do
   res - parseFile fn
   case res of
 ParseOk mod - when (hasNPlusK mod) $ putStrLn fn
 _ - return ()

 main :: IO ()
 main = mapM_ printIfNPlusK = getArgs
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Interesting Thread on OO Usefulness (scala mailing list)

2009-05-05 Thread Wolfgang Jeltsch
Am Montag, 4. Mai 2009 13:35 schrieb Bulat Ziganshin:
 Hello Paolo,

 Monday, May 4, 2009, 2:05:44 PM, you wrote:
  Martin Odersky advocates the OO features of the scala language
  proposing an interesting problem where the OO approach seams
  valuable.

 i know two problems in Haskell/GHC that require OO-loke features -
 extensible exceptions and GUI widget types hierarchy

Note that you don’t need different types for different kinds of GUI widgets if 
you use Functional Reactive Programming (FRP). You need different types if 
you use OO because you have to explicitely modify widgets after you have 
created them, and what modifications you are allowed to do, depends on the 
kind of widget. With FRP, you specify the behavior over all time when you 
create the widget, so no need for later method calls.

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


Re[2]: [Haskell-cafe] Interesting Thread on OO Usefulness (scala mailing list)

2009-05-05 Thread Bulat Ziganshin
Hello Wolfgang,

Tuesday, May 5, 2009, 8:27:17 PM, you wrote:

 i know two problems in Haskell/GHC that require OO-loke features -
 extensible exceptions and GUI widget types hierarchy

 Note that you don’t need different types for different kinds of GUI widgets if
 you use Functional Reactive Programming (FRP). You need different types if
 you use OO because you have to explicitely modify widgets after you have
 created them, and what modifications you are allowed to do, depends on the
 kind of widget. With FRP, you specify the behavior over all time when you
 create the widget, so no need for later method calls.

(i don't know anything about FRP)

i think it doesn't change anything. the main reason why i need common
operations is because i write generic procedures. another erason os
what i can't remember 100 individual 'setSize' operations for 100
types of widgets. so we need to have some generic names, short of they
are used due initialization or later

-- 
Best regards,
 Bulatmailto:bulat.zigans...@gmail.com

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


[Haskell-cafe] ANN: BUG FIX release of regex-tdfa-1.1.2

2009-05-05 Thread ChrisK
Hello,

  While occasionally and slowly updating the future version of regex-tdfa I
found a bug that exists in the released 1.1.1 version.  It was just a matter of
passing the wrong value into a function, so was easy to fix when I figured it 
out.

  The test case triggered an impossible error call and so I know this can kill
a program that uses a buggy version of this library.

  Please upgrade regex-tdfa to version 1.1.2 which is available on hackage at:

http://hackage.haskell.org/cgi-bin/hackage-scripts/package/regex-tdfa

Cheers,
  Chris

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


[Haskell-cafe] calling a variable length parameter lambda expression

2009-05-05 Thread Nico Rolle
Hi everyone.

I have a problem.
A function is recieving a lambda expression like this:
(\ x y - x  y)
or like this
(\ x y z a - (x  y)  (z  a)

my problem is now i know i have a list filled with the parameters for
the lambda expression.
but how can i call that expression?
[parameters] is my list of parameters for the lambda expression.
lambda_ex is my lambda expression

is there a function wich can do smth like that?

lambda _ex (unfold_parameters parameters)

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


Re: [Haskell-cafe] calling a variable length parameter lambda expression

2009-05-05 Thread Miguel Mitrofanov

Short answer: that's impossible.

Well, with some oleging it should be possible, but the very fact that  
you're trying to do something like this indicates that you're doing  
something wrong. Where did this list of parameters came from? May be,  
you can apply your function to them one at a time, as they arrive?


On 5 May 2009, at 20:49, Nico Rolle wrote:


Hi everyone.

I have a problem.
A function is recieving a lambda expression like this:
(\ x y - x  y)
or like this
(\ x y z a - (x  y)  (z  a)

my problem is now i know i have a list filled with the parameters for
the lambda expression.
but how can i call that expression?
[parameters] is my list of parameters for the lambda expression.
lambda_ex is my lambda expression

is there a function wich can do smth like that?

lambda _ex (unfold_parameters parameters)

best regards
___
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] calling a variable length parameter lambda expression

2009-05-05 Thread Ryan Ingram
This is a Hard Problem in Haskell.

Let me ask you, how many parameters does this function take?
a = (\x - x)

How many parameters does this function take?
b = (\f x - f x)

How many parameters does this function take?
c = (\f x y - f x y)

What if I call
a (+)?

  -- ryan

On Tue, May 5, 2009 at 9:49 AM, Nico Rolle nro...@web.de wrote:
 Hi everyone.

 I have a problem.
 A function is recieving a lambda expression like this:
 (\ x y - x  y)
 or like this
 (\ x y z a - (x  y)  (z  a)

 my problem is now i know i have a list filled with the parameters for
 the lambda expression.
 but how can i call that expression?
 [parameters] is my list of parameters for the lambda expression.
 lambda_ex is my lambda expression

 is there a function wich can do smth like that?

 lambda _ex (unfold_parameters parameters)

 best regards
 ___
 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] Parsec - Custom Fail

2009-05-05 Thread Daniel Fischer
Am Dienstag 05 Mai 2009 17:38:35 schrieb mwin...@brocku.ca:
 Thanks, but I want a nice solution not another, even more complicated,
 workaround.

I'm afraid you're out of luck there.

Parsec carries a ParseError around even for successful parses (where it's a 
SourcePos and 
and empty list of messages).
When binding two parsers, if the second doesn't consume any input, for the 
overall result 
it calls mergeErrorReply, which calls mergeError from 
Text.ParserCombinators.Parsec.Error:

mergeError :: ParseError - ParseError - ParseError
mergeError (ParseError pos msgs1) (ParseError _ msgs2)
= ParseError pos (msgs1 ++ msgs2)

So that doesn't look at the position of the second error :(

You could change the sources of parsec, the least intrusive would probably be 
to modify 
mergeError:

mergeError :: ParseError - ParseError - ParseError
mergeError (ParseError _ []) pe2 = pe2
mergeError (ParseError pos msgs1) (ParseError _ msgs2)
= ParseError pos (msgs1 ++ msgs2)

or you could employ an ugly workaround like

setPosAndFail :: tok - SourcePos - String - GenParser tok st a
setPosAndFail dummy pos msg = do
setPosition pos
inp - getInput
setInput (dummy:inp)
tokenPrim (const ) (\p _ _ - p) Just
fail msg

myFail :: SourcePos - String - GenParser Char st a
myFail = setPosAndFail 'a'

to pretend you actually consumed some input.
It works:

*TestWorkAround test
Left (line 100, column 100):
Test

but isn't pretty.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] applicative challenge

2009-05-05 Thread Thomas Hartman
 interact (\s - let (first,second) = span (not . null) (lines s)
   in unlines (first:first++second:takeWhile (not.null) second))

So, that didn't quite do the right thing, and it seemed like using
span/break wouldn't scale well for more than two iterations. Here's
another attempt, which is a little closer I think, except that it
seems to be using some sort of half-assed state without being explicit
about it:

module Main where

t17 = interact f17
f17 s = let (first,rest) = grabby s
(second,_) = grabby rest
in first\n ++ first ++ second\n ++ second

grabby :: String - (String,String)
grabby s =
  let (beg,end) = break null . lines $ s
  in (unlines beg, (unlines . drop 2 $ end))


2009/5/5 Ketil Malde ke...@malde.org:
 Thomas Hartman tphya...@gmail.com writes:

 That's slick, but is there some way to use interact twice in the same 
 program?

 No :-)

 t10 =
   let f = unlines . takeWhile (not . blank) . lines
   in  do putStrLn first time
          interact f
          putStrLn second time
          interact f

 this results in *** Exception: stdin: hGetContents: illegal
 operation (handle is closed) -}

 Yes. Interacting uses hGetContents, and hGetContents semi-closes (or
 fully-closes) the handle.  If you do it from GHCi, you only get to run
 your program once.

 I also tried

 t15 =
   let grabby = unlines . takeWhile (not . blank) . lines
       top = (first time:  ++) . grabby . (second time:  ++) . grabby
   in  interact top

 but that didn't work either:
 thart...@ubuntu:~/haskell-learning/lazy-n-strictrunghc sequencing.hs
 a
 first time: second time: a
 b
 b

 Well - the input to the leftmost grabby is second time prepended to
 the input from the first, and then you prepend first time - so this
 makes sense.

 Something like this, perhaps:

 interact (\s - let (first,second) = span (not . null) (lines s)
                in unlines (first:first++second:takeWhile (not.null) 
 second))

 If someone can explain the subtleties of using interact when you run
 out of stdio here, it would be nice to incorporate this into

 hGetContents - there can only be one.

 -k
 --
 If I haven't seen further, it is by standing in the footprints of giants

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


Re: FW: Re: [Haskell-cafe] calling a variable length parameter lambda expression

2009-05-05 Thread Ryan Ingram
On Tue, May 5, 2009 at 10:05 AM, Nico Rolle nro...@web.de wrote:
 I dont't understand why u ask me that but the lambda expression will
 only get values not functions as a parameter.
 a = 1
 b = 2
 c = 3

 What if I call
 a (+)?

 this won't happen in my use case.
 regards nico

Here's an example for a single fixed argument and return types:

class LambdaApply lam where
lamApply :: lam - [Integer] - Bool

instance LambdaApply Bool where
   lamApply b [] = b
   lamApply _ _ = error Too many arguments in argument list

instance LambdaApply r = LambdaApply (Integer - r) where
  lamApply _ [] = error Not enough arguments in argument list
  lamApply f (x:xs) = lamApply (f x) xs

The problem is generalizing this to any type, because of the base case:

instance LambdaApply r where
   lamApply r [] = r
   lamApply _ _ = error Too many arguments in argument list

overlaps with function types such as (Integer - a).

Since you say this is only for value types, if you're willing to
encode each value type you care about, you can make this work in a
somewhat more general way.  But unless you are just using it for
syntactic sugar (which seems unlikely for this use case), it's usually
a signal that you are doing something wrong.

  -- ryan

 Von: Ryan Ingram ryani.s...@gmail.com
 Gesendet: 05.05.09 18:58:32
 An: Nico Rolle nro...@web.de
 CC: haskell-cafe@haskell.org
 Betreff: Re: [Haskell-cafe] calling a variable length parameter lambda  
 expression

 This is a Hard Problem in Haskell.

 Let me ask you, how many parameters does this function take?
 a = (\x - x)

 How many parameters does this function take?
 b = (\f x - f x)

 How many parameters does this function take?
 c = (\f x y - f x y)

 What if I call
 a (+)?

   -- ryan

 On Tue, May 5, 2009 at 9:49 AM, Nico Rolle nro...@web.de wrote:
  Hi everyone.
 
  I have a problem.
  A function is recieving a lambda expression like this:
  (\ x y - x  y)
  or like this
  (\ x y z a - (x  y)  (z  a)
 
  my problem is now i know i have a list filled with the parameters for
  the lambda expression.
  but how can i call that expression?
  [parameters] is my list of parameters for the lambda expression.
  lambda_ex is my lambda expression
 
  is there a function wich can do smth like that?
 
  lambda _ex (unfold_parameters parameters)
 
  best regards
  ___
  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] calling a variable length parameter lambda expression

2009-05-05 Thread Ketil Malde
Nico Rolle nro...@web.de writes:

 A function is recieving a lambda expression like this:
 (\ x y - x  y)
 or like this
 (\ x y z a - (x  y)  (z  a)

And the type of that function is..?

 my problem is now i know i have a list filled with the parameters for
 the lambda expression.   but how can i call that expression?

 [parameters] is my list of parameters for the lambda expression.
 lambda_ex is my lambda expression

Would this work?

  data LambdaExpr a = L0 a | L1 (a - a) | L2 (a - a - a) | ...

  apply :: LambdaExpr a - [a] - a
  apply (L0 x) _ = x
  apply (L1 f) (x:_) = f x
  apply (L2 f) (x1:x2:_) = f x1 s2
   :

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


using interact with state, was Re: [Haskell-cafe] applicative challenge

2009-05-05 Thread Thomas Hartman
Aha!

There is in fact a way to fit this specification into the applicative paradigm.

I'm a bit muzzy as to what it all means, but I must say, aesthetically
I'm rather pleased with the result:

module Main where

import Control.Monad.State
import Control.Applicative
import Control.Applicative.State -- applicative-extras on hackage

-- works
t18 = interact $ evalState f18
  where f18 = return paint `ap` grabTillBlank `ap` grabTillBlank
paint first second = first\n ++ first ++ second\n ++ second

grabTillBlank = State $ \s -
  let (beg,end) = break null . lines $ s
  in  (unlines beg, (unlines . drop 2 $ end))

-- And, with applicative extras:
t19 = interact $ evalState f19
  where f19 = paint $ grabTillBlank * grabTillBlank
paint first second = first\n ++ first ++ second\n ++ second




2009/5/5 Thomas Hartman tphya...@gmail.com:
 interact (\s - let (first,second) = span (not . null) (lines s)
               in unlines (first:first++second:takeWhile (not.null) 
 second))

 So, that didn't quite do the right thing, and it seemed like using
 span/break wouldn't scale well for more than two iterations. Here's
 another attempt, which is a little closer I think, except that it
 seems to be using some sort of half-assed state without being explicit
 about it:

 module Main where

 t17 = interact f17
 f17 s = let (first,rest) = grabby s
            (second,_) = grabby rest
        in first\n ++ first ++ second\n ++ second

 grabby :: String - (String,String)
 grabby s =
  let (beg,end) = break null . lines $ s
  in (unlines beg, (unlines . drop 2 $ end))


 2009/5/5 Ketil Malde ke...@malde.org:
 Thomas Hartman tphya...@gmail.com writes:

 That's slick, but is there some way to use interact twice in the same 
 program?

 No :-)

 t10 =
   let f = unlines . takeWhile (not . blank) . lines
   in  do putStrLn first time
          interact f
          putStrLn second time
          interact f

 this results in *** Exception: stdin: hGetContents: illegal
 operation (handle is closed) -}

 Yes. Interacting uses hGetContents, and hGetContents semi-closes (or
 fully-closes) the handle.  If you do it from GHCi, you only get to run
 your program once.

 I also tried

 t15 =
   let grabby = unlines . takeWhile (not . blank) . lines
       top = (first time:  ++) . grabby . (second time:  ++) . grabby
   in  interact top

 but that didn't work either:
 thart...@ubuntu:~/haskell-learning/lazy-n-strictrunghc sequencing.hs
 a
 first time: second time: a
 b
 b

 Well - the input to the leftmost grabby is second time prepended to
 the input from the first, and then you prepend first time - so this
 makes sense.

 Something like this, perhaps:

 interact (\s - let (first,second) = span (not . null) (lines s)
                in unlines (first:first++second:takeWhile (not.null) 
 second))

 If someone can explain the subtleties of using interact when you run
 out of stdio here, it would be nice to incorporate this into

 hGetContents - there can only be one.

 -k
 --
 If I haven't seen further, it is by standing in the footprints of giants


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


Re: [Haskell-cafe] ST.Lazy vs ST.Strict

2009-05-05 Thread Tobias Olausson
This simple implementation of CPU does not behave as expected in the
latest version of  ghc using ST.Lazy since it updates the `pc` in the
wrong order.
When we use ghc-6.8 the code works as expected both with lazy and strict ST.
How is that? How do we fix this so we can use ghc-6.10.

-- --
module Main where

import Control.Monad.Reader
import Control.Monad.ST.Lazy
import Data.STRef.Lazy
import Data.Array.ST
import Int

data Refs s = Refs
{ memory:: STArray s Int8 Int8
, pc:: STRef s Int8
}

type CPU s a = ReaderT (Refs s) (ST s) a
type Address = Int8
type OPCode  = Int8

alterVar v f = asks v = lift . flip modifySTRef f
getVar v = asks v = lift . readSTRef
setVar v a = asks v = lift . flip writeSTRef a

readMem :: Int8 - CPU s Int8
readMem addr = asks memory = lift . flip readArray addr

writeMem :: Address - Int8 - CPU s ()
writeMem addr v = asks memory = \r - lift $ writeArray r addr v

fetch :: CPU s OPCode
fetch = getVar pc = \v - alterVar pc (+1)  readMem v

execute :: OPCode - CPU s ()
execute op = case op of
0x4 - alterVar pc (+100) -- should run this
_   - error should never match this

initCPU :: ST s (Refs s)
initCPU = do
m - newArray_ (0,30)
p - newSTRef 0
return (Refs m p)

main :: IO ()
main = do
print $ runST (initCPU = runReaderT m)
  where
m = do
  writeMem 0 0x4
  writeMem 1 0x10
  op - fetch
  execute op
  getVar pc
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Performance counters

2009-05-05 Thread Andrew Coppin

Magnus Therning wrote:

Andrew Coppin wrote:
Stuff like how many times does this function get called? How what's 
the maximum depth it recurses to? That kind of thing.


It won't help you, but wouldn't it be the kind of thing that'd fit in 
the GHC runtime?


Do you also require that the counters are available to the program 
itself?


(This is starting to sound like something Don mentioned in his talk in 
London...)


[I'm getting *really* tired of my ISP thinking that 30% of the traffic 
from Haskell-cafe is spam. If only there was a way to whitelist it or 
something... repeatedly clicking this is not spam doesn't seem to get 
the message across.]


Um... hmm, that's a good question. Basically I've written a program that 
does adaptive sampling, and I want to see how much it's recursing. There 
are two parameters you can adjust: the minimum step size, and the 
maximum error tollerance. I'd like to know which of the two limits the 
program is reaching. (In other words, does the error eventually fall 
below the threshold, or does the step size become too small first?)


I guess *ideally* I'd like the end user to be able to find this out from 
the running program... but I guess to do that there really is no other 
way than to sprinkle monads or unsafe I/O around the place.


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


Re: [Haskell-cafe] ST.Lazy vs ST.Strict

2009-05-05 Thread Daniel Fischer
Am Dienstag 05 Mai 2009 21:42:00 schrieb Tobias Olausson:
 This simple implementation of CPU does not behave as expected in the
 latest version of  ghc using ST.Lazy since it updates the `pc` in the
 wrong order.
 When we use ghc-6.8 the code works as expected both with lazy and strict
 ST. How is that? How do we fix this so we can use ghc-6.10.

Fix 1: compile with optimisations.
The sample code worked here with that.

Fix 2: change fetch:

 fetch :: CPU s OPCode
 fetch = getVar pc = \v - alterVar pc (+1)  readMem v

The lazy ST doesn't actually read the STRef before readMem v is called, so it 
reads the 
altered STRef and consequently the wrong memory address. Make sure that v is 
determined 
before the STRef is altered, e.g. by

fetch = getVar pc = \v - v `seq` (alterVar pc (+1)  readMem v)

or

fetch = do
v - getVar pc
w - readMem v
alterVar pc succ
return w
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Performance counters

2009-05-05 Thread minh thu
2009/5/5 Andrew Coppin andrewcop...@btinternet.com:
 Magnus Therning wrote:

 Andrew Coppin wrote:

 Stuff like how many times does this function get called? How what's the
 maximum depth it recurses to? That kind of thing.

 It won't help you, but wouldn't it be the kind of thing that'd fit in the
 GHC runtime?

 Do you also require that the counters are available to the program itself?

 (This is starting to sound like something Don mentioned in his talk in
 London...)

 [I'm getting *really* tired of my ISP thinking that 30% of the traffic from
 Haskell-cafe is spam. If only there was a way to whitelist it or
 something... repeatedly clicking this is not spam doesn't seem to get the
 message across.]

 Um... hmm, that's a good question. Basically I've written a program that
 does adaptive sampling, and I want to see how much it's recursing. There are
 two parameters you can adjust: the minimum step size, and the maximum error
 tollerance. I'd like to know which of the two limits the program is
 reaching. (In other words, does the error eventually fall below the
 threshold, or does the step size become too small first?)

 I guess *ideally* I'd like the end user to be able to find this out from the
 running program... but I guess to do that there really is no other way than
 to sprinkle monads or unsafe I/O around the place.

Hi,

Since your recursive function has to test if the recursion should be
ended or continued,
when it ends, you know the reason. So why not just wrap your result
inside something like:

data Result a = ThresholdReached a | StepSizeTooSmall a

?

Also, passing an accumulator to the function to record the number of
steps should be
straightforward.

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


Re: [Haskell-cafe] ST.Lazy vs ST.Strict

2009-05-05 Thread Luke Palmer
On Sun, May 3, 2009 at 11:27 AM, Tobias Olausson tob...@gmail.com wrote:

 Hello!
 I have a program that is using ST.Strict, which works fine.
 However, the program needs to be extended, and to do that,
 lazy evaluation is needed. As a result of that, I have switched
 to ST.Lazy to be able to do stuff like



 foo y = do
x - something
xs - foo (y+1)
return (x:xs)


As Ryan points out, this will not do what you want.  But that is incidental,
not essential:

foo y = do
 x - something
 fmap (x:) $ foo (y+1)

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


Re: [Haskell-cafe] ST.Lazy vs ST.Strict

2009-05-05 Thread Luke Palmer
On Tue, May 5, 2009 at 3:27 PM, Luke Palmer lrpal...@gmail.com wrote:

 On Sun, May 3, 2009 at 11:27 AM, Tobias Olausson tob...@gmail.com wrote:

 Hello!
 I have a program that is using ST.Strict, which works fine.
 However, the program needs to be extended, and to do that,
 lazy evaluation is needed. As a result of that, I have switched
 to ST.Lazy to be able to do stuff like



 foo y = do
x - something
xs - foo (y+1)
return (x:xs)


 As Ryan points out, this will not do what you want.  But that is
 incidental, not essential:

 foo y = do
  x - something
  fmap (x:) $ foo (y+1)


Questioning my own reasoning, I must apologize.   I was wrong, these two
programs are identical and both do what you want.

Any references to the state *after* the infinite chain of foos will result
in _|_, but as long as something is the only place that state calls occur,
you will be fine.

I also suspect that ST.Lazy should be no less defined than ST.Strict in all
cases, modulo unsafe operations of course (you aren't doing those, are
you?), so you have encountered a bug.  Minimize the test case and submit a
bug report :-)

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


Re: [Haskell-cafe] ANN: atom-0.0.3

2009-05-05 Thread Tom Hawkins
I pushed out a new version of atom that incorporates some of John's
recommendations (thanks John).  And it ships with a slightly better
example.

The release also includes means to extract code coverage to track
which atom rules have fired during testing.

-Tom

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

On Tue, May 5, 2009 at 4:06 AM, John Van Enk vane...@gmail.com wrote:
 If any one has been looking at this and wants another example, I've finished
 two posts on the topic of Atom.

 These posts depend on a patch:
 http://code.sw17ch.com/blog/atom/atom_0.0.2_sw17ch_1.diff

 Part 1: http://blog.sw17ch.com/wordpress/?p=84 - Brief discussion and
 describes the patch
 Part 2: http://blog.sw17ch.com/wordpress/?p=111 - Writing a program to
 blink an LED.

 Feed back would be appreciated!

 /jve

 On Sun, Apr 26, 2009 at 4:39 PM, Tom Hawkins tomahawk...@gmail.com wrote:

 Atom is a DSL in Haskell for designed hard realtime embedded programs.
  At Eaton, we are using it to control hydraulic hybrid refuse trucks
 and shuttle buses.  After my talk at CUFP
 (http://cufp.galois.com/2008/schedule.html), a few people inquired
 about atom -- I finally had a chance to upload it to Hackage.

 http://hackage.haskell.org/cgi-bin/hackage-scripts/package/atom-0.0.2

 Some new enhancements:
 - A simple rule scheduler for load balancing.
 - Signal probing for debug and data logging.
 - Functional coverage to monitor which rules have executed.
 - Started integration with the Yices SMT solver for bounded model
 checking.

 Experiences with our Eaton project:
 - 5K lines of Haskell/atom replaced 120K lines of matlab, simulink,
 and visual basic.
 - 2 months to port simulink design to atom.
 - 3K lines of atom generates 22K lines of embedded C.
 - Design composed of 450 atomic state transition rules.
 - Rules with execution periods from 1ms to 10s all scheduled at
 compile time to a 1 ms main loop.
 - 3 minute compilation time from atom source to ECU.
 - Atom design clears electronic/sw testing on first pass.
 - Currently in vehicle testing with no major issues.


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


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


[Haskell-cafe] Re: Tests

2009-05-05 Thread John Goerzen
Guenther Schmidt wrote:
 let me first of all thank you for providing the HDBC package. Haskell 
 would be a much, much less usefull language without a working database 
 interface. I could certainly not have written the app in  Haskell 
 without it and in any other language I know writing this app would have 
 been much more difficult.

Thanks!  I'm glad you found it (and Real World Haskell) helpful.

 The problem is what's in the database.
 
 You'd think there'd be a Günni in the database, right?
 
 Wrong!
 
 At least this is where your library and Sqlite disagree. Sqlite with any 
 GUI client doesn't show a Günni, it shows a G!$%§$§%nni. So do MS 
 Access and MySql btw.

And now that is REALLY weird, because I can't duplicate it here.

I wrote this little Haskell program:

import Database.HDBC
import Database.HDBC.Sqlite3

main = do dbh - connectSqlite3 foo.db
  run dbh CREATE TABLE foo (bar text) []
  run dbh INSERT INTO foo VALUES (?) [toSql Günther]
  run dbh INSERT INTO foo VALUES (?) [toSql 2-G\252nther]
  commit dbh
  disconnect dbh

And when I inspect foo.db with the sqlite3 command-line tool:

/tmp$ sqlite3 foo.db
SQLite version 3.5.9
Enter .help for instructions
sqlite select * from foo;
Günther
2-Günther

Exactly correct, as expected.

I can read it back correctly from Haskell, too:

import Database.HDBC
import Database.HDBC.Sqlite3
import qualified System.IO.UTF8 as U

main = do dbh - connectSqlite3 foo.db
  results - quickQuery' dbh SELECT * from foo []
  mapM_ ((print :: String - IO ()) . fromSql . head) results
  mapM_ (U.putStrLn . fromSql . head) results
  disconnect dbh

and when I run this:

/tmp$ ./foo3a
G\252nther
2-G\252nther
Günther
2-Günther

I wonder if there is something weird about your environment: non-unicode
terminals, databases, editors, or something?

For me, it Just Works as it should.



 
 For now I managed to rollback the UTF8 code in the HDBC-2.1 and got my 
 app to work as needed.
 
 I hope you find this info useful, thanks once more
 
 Günther
 
 

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


Re: [Haskell-cafe] applicative challenge

2009-05-05 Thread Thomas Hartman
 half-assed state

for a real state solution, there's follow up here:

http://groups.google.com/group/haskell-cafe/browse_thread/thread/d6143504c0e80075

2009/5/5 Thomas Hartman tphya...@gmail.com:
 interact (\s - let (first,second) = span (not . null) (lines s)
               in unlines (first:first++second:takeWhile (not.null) 
 second))

 So, that didn't quite do the right thing, and it seemed like using
 span/break wouldn't scale well for more than two iterations. Here's
 another attempt, which is a little closer I think, except that it
 seems to be using some sort of half-assed state without being explicit
 about it:

 module Main where

 t17 = interact f17
 f17 s = let (first,rest) = grabby s
            (second,_) = grabby rest
        in first\n ++ first ++ second\n ++ second

 grabby :: String - (String,String)
 grabby s =
  let (beg,end) = break null . lines $ s
  in (unlines beg, (unlines . drop 2 $ end))


 2009/5/5 Ketil Malde ke...@malde.org:
 Thomas Hartman tphya...@gmail.com writes:

 That's slick, but is there some way to use interact twice in the same 
 program?

 No :-)

 t10 =
   let f = unlines . takeWhile (not . blank) . lines
   in  do putStrLn first time
          interact f
          putStrLn second time
          interact f

 this results in *** Exception: stdin: hGetContents: illegal
 operation (handle is closed) -}

 Yes. Interacting uses hGetContents, and hGetContents semi-closes (or
 fully-closes) the handle.  If you do it from GHCi, you only get to run
 your program once.

 I also tried

 t15 =
   let grabby = unlines . takeWhile (not . blank) . lines
       top = (first time:  ++) . grabby . (second time:  ++) . grabby
   in  interact top

 but that didn't work either:
 thart...@ubuntu:~/haskell-learning/lazy-n-strictrunghc sequencing.hs
 a
 first time: second time: a
 b
 b

 Well - the input to the leftmost grabby is second time prepended to
 the input from the first, and then you prepend first time - so this
 makes sense.

 Something like this, perhaps:

 interact (\s - let (first,second) = span (not . null) (lines s)
                in unlines (first:first++second:takeWhile (not.null) 
 second))

 If someone can explain the subtleties of using interact when you run
 out of stdio here, it would be nice to incorporate this into

 hGetContents - there can only be one.

 -k
 --
 If I haven't seen further, it is by standing in the footprints of giants


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


Re: [Haskell-cafe] Thread on scala ml: Usefulness of OOP

2009-05-05 Thread Brandon S. Allbery KF8NH

On May 4, 2009, at 06:19 , Paolo Losi wrote:

http://www.nabble.com/-scala--usefulness-of-OOP-td23268250.html

Martin Odersky, scala creator, advocates the use of OOP using
an interesting toy problem.
I would be very interested about the haskell point of view on the  
topic.

Is there any haskell guru that wants to take a stub at the problem
or give his opinion?



Did you read the HaskellWiki link given in the comments?
http://haskell.org/haskellwiki/OOP_vs_type_classes
The top of the page suggests it's incomplete but there is a lot of  
stuff in there including example code.


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




PGP.sig
Description: This is a digitally signed message part
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] A brief note on n_k patterns and Hackage

2009-05-05 Thread Richard O'Keefe


On 5 May 2009, at 8:30 pm, Magnus Therning wrote:

On Tue, May 5, 2009 at 1:04 AM, Richard O'Keefe o...@cs.otago.ac.nz  
wrote:

I never really understood why it was thought to be relevant,
but I was challenged to show that n+k patterns occurred in
Hackage.


Why is it relevant?


Some people think that the popularity of a feature in
an openly accessible collection of Haskell sources is
relevant to whether it should continue to be supported,
in a way that, say, appearance in textbooks, utility
to beginners, and contribution to readability are not.
Apparently.

I don't understand this.  n+k patterns are the ONLY
Haskell98 feature scheduled for removal from Haskell'.

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


Re: [Haskell-cafe] A brief note on n_k patterns and Hackage

2009-05-05 Thread Don Stewart
ok:
 On 5 May 2009, at 8:30 pm, Magnus Therning wrote:

 On Tue, May 5, 2009 at 1:04 AM, Richard O'Keefe o...@cs.otago.ac.nz  
 wrote:
 I never really understood why it was thought to be relevant,
 but I was challenged to show that n+k patterns occurred in
 Hackage.

 Why is it relevant?

 Some people think that the popularity of a feature in
 an openly accessible collection of Haskell sources is
 relevant to whether it should continue to be supported,
 in a way that, say, appearance in textbooks, utility
 to beginners, and contribution to readability are not.
 Apparently.

This was the main reason it was kept in Haskell 98, 11 years ago.
New textbooks don't use it (RWH doesn't talk or recommend the use of n+k)
 
 I don't understand this.  n+k patterns are the ONLY
 Haskell98 feature scheduled for removal from Haskell'.

For multiple reasons, summarised here:

http://hackage.haskell.org/trac/haskell-prime/wiki/RemoveNPlusK

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


Re: [Haskell-cafe] List comprehension

2009-05-05 Thread porges



2009/5/6 Bulat Ziganshin bulat.zigans...@gmail.com:

Hello applebiz89,

Tuesday, May 5, 2009, 7:20:35 PM, you wrote:


filmsInGivenYear :: Int - [Film] - [String]
filmsInGivenYear filmYear ?= [ title | year - (Film title director year
fans) , year == filmYear] (this code wont compile - error given '?Syntax
error in expression (unexpected `;', possibly due to bad layout)')


you forget films list variable:

filmsInGivenYear filmYear films =
 [ title | (Film title director year fans) - films, year == filmYear]


And this is nicer if you define Film with records:

-- just guessing as to types
data Film = Film { title :: String, director :: String, year :: Int, fans :: 
[Fan] }

filmsInGivenYear filmYear films = [title | film - films, year film == filmYear]

-- and then it's probably easier written as:
filmsInGivenYear filmYear films = filter (\film - year film == filmYear) films

-- or slightly simpler:
filmsInGivenYear filmYear = filter (\film - year film == filmYear)

-- or with Data.Function.Predicate (shameless plug) 
http://hackage.haskell.org/packages/archive/predicates/0.1/doc/html/Data-Function-Predicate.html:
filmsInGivenYear filmYear = filter (year `equals` filmYear)

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


Re: [Haskell-cafe] calling a variable length parameter lambda expression

2009-05-05 Thread Richard O'Keefe


On 6 May 2009, at 4:49 am, Nico Rolle wrote:


Hi everyone.

I have a problem.
A function is recieving a lambda expression like this:
(\ x y - x  y)
or like this
(\ x y z a - (x  y)  (z  a)


Your first function has type
Ord a = a - a - Bool
so your list of parameters must have type
Ord a = [a]
and length 2.

Your second function -- and why do you have the excess parentheses?
they make it harder to read -- has type
Ord a = a - a - a - Bool
so your list of parameters must have type
Ord a = [a]
and length 3.


but how can i call that expression?
[parameters] is my list of parameters for the lambda expression.
lambda_ex is my lambda expression

is there a function wich can do smth like that?

lambda _ex (unfold_parameters parameters)


but in both cases lambda_ex wants a single Ord,
so unfold_parameters parameters would have to
return just that Ord.

You _could_ fake something up for this case using
type classes, but the big question is WHY do you
want to do this?  It makes sense for Lisp or Scheme,
but not very much sense for a typed language.

Why are you building a list [x,y] or [x,y,z]
rather than a function (\f - f x y) or
(\f - f x y z) so that you can do
parameters lambda_ex?

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


Re: [Haskell-cafe] Re: Is Haskell a Good Choice for Web Applications? (ANN: Vocabulink)

2009-05-05 Thread wren ng thornton

Chris Forno (jekor) wrote:

The idea is that I spent years studying different languages, generally
with a textbook. The textbooks tend to focus on teaching rules and
grammar, with a little bit of vocabulary and dialog each chapter. I
think the focus should be reversed.


This varies wildly by textbook, with some bias for the language being 
taught. Personally I've found too many vocabulary textbooks and  far too 
few grammar textbooks (that is, actual *grammar* textbooks not 
sentence-sized-vocabulary textbooks).




Obviously grammar is very important. But is reading about it effective
for everyone? 


In my experience learning and teaching languages, this too varies wildly 
by learner. Some people do better with an examples first or 
vocabulary based style where they must come to an intuition of the 
grammar rules; other people (such as myself) do better with a rules 
first or grammar based style where they must come to learn vocabulary 
on their own.


Neither variety of person is superior nor, as far as I can tell, more 
common at large; so any good teacher or textbook should balance these 
bottom up and top down approaches. IMO vocabulary is easy to learn, 
it just takes time, whereas grammar is harder to figure out on one's 
own, and so is the better thing for a teacher to focus on. However, this 
says little about reference material (as opposed to learning material), 
and study guides walk a line between reference and teaching.


JGram http://jgram.org/pages/viewList.php is an interesting study 
guide that takes a middle path, treating syntactic patterns the same as 
it does lexemes. This is particularly appropriate for a language like 
Japanese where it's not always immediately apparent whether something 
belongs to the grammar vs the lexicon.




The only way I
successfully became fluent in a language (Esperanto) was through
immersion,


This is, hands down, the best way to learn any language. For it to work, 
as you say, some vocabulary is necessary; however, I think the amount of 
vocabulary needed at first is not so large as some think. Daily 
small-talk for getting/giving directions, ordering food, and the like 
comprise a large portion of beginner's language and requires remarkably 
little breadth of vocabulary (a couple hundred words or so). Small-talk 
also includes some of the most obscure and difficult-to-master 
grammatical patterns like greetings, getting the right tone of 
politeness/familiarity, and knowing what sorts of sentence fragments and 
other ungrammatical patterns are perfectly acceptable.




And of course it has very forgiving sentence and a rather simple
grammar, but I'm finding the experience to be very similar with Japanese
so far.

That being said, Esperanto, and even Japanese sentence structure perhaps
is not as different as an agglutinative language like German. I'll need
to study it more to find out.


Actually, Japanese is agglutinative too (moreso than German is). The 
basic structures of Japanese are quite simple, however the details 
needed for fluency are quite intricate. Phrase order is rather free, 
though it is not entirely free and it is easy to reorder things so that 
they no longer make sense to native speakers. Aside from a few of the 
common mistakes beginners make, if you mess up the cases/particles 
you'll end up with gibberish.


--
Live well,
~wren
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] setResourceLimit

2009-05-05 Thread Brandon S. Allbery KF8NH

On May 5, 2009, at 04:52 , br...@lorf.org wrote:

I have a long-lived multithreaded server process that needs to execute
programs and interact with them via Handles. The programs could
misbehave, like loop or hang, so I need to limit the real and CPU time
they can take.

I guess System.Posix.Resource.setResourceLimit sets limits on the
current process, so I can't use it in the server process. Is it a good
approach to write some utility program for the server to call that  
does

setResourceLimit and executes the programs that could misbehave?



An alternative is to forkProcess and have the child setResourceLimit  
and then executeFile.


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




PGP.sig
Description: This is a digitally signed message part
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] runhaskell CLI parameters

2009-05-05 Thread Vasili I. Galchin
Hello,

 I have forgotten the runhaskell CLI parameters ... sigh. In particular
I want to a local build of a set of of package:

 runhaskell Setup.hs configure --user???

I just did a runhaskell -? which didn't tell me a lot!

Kind regards,

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


Re: [Haskell-cafe] runhaskell CLI parameters

2009-05-05 Thread Brandon S. Allbery KF8NH

On May 5, 2009, at 23:39 , Vasili I. Galchin wrote:
 I have forgotten the runhaskell CLI parameters ... sigh. In  
particular I want to a local build of a set of of package:


 runhaskell Setup.hs configure --user???



That's not an option to runhaskell, but an option to Setup.hs.

  runhaskell Setup.hs configure --help

to see what options you can use with the configure command.

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




PGP.sig
Description: This is a digitally signed message part
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: runhaskell CLI parameters

2009-05-05 Thread mail
Vasili I. Galchin vigalc...@gmail.com writes:

 Hello,

  I have forgotten the runhaskell CLI parameters ... sigh. In particular I
 want to a local build of a set of of package:

  runhaskell Setup.hs configure --user???

 I just did a runhaskell -? which didn't tell me a lot!

Try runhaskell Setup.hs --help. runhaskell's help isn't very useful
here, because the program you're interested in is actually Setup.hs.

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


[Haskell-cafe] ANNOUNCE: The Haskell Platform

2009-05-05 Thread Don Stewart

We're pleased to announce the first release of the Haskell Platform:
a single, standard Haskell distribution for every system.

Download the Haskell Platform 2009.2.0 installers and specification:

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

The Haskell Platform is a blessed library and tool suite for Haskell
culled from Hackage, along with installers for a wide variety of
systems. It saves developers work picking and choosing the best Haskell
libraries and tools to use for a task. 

What you get:

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

With regular time-based releases, we expect the platform will grow into
a rich, indispensable development environment for all Haskell projects.

Distro maintainers that support the Haskell Platform can be confident
they're fully supporting Haskell as the developers intend it. Developers
targetting the platform can be confident they have a trusted base of
code to work with.

*Please note that this is a beta release*. We do not expect all the
installers to work perfectly, nor every developer need met, and we would
appreciate feedback.

You can help out by packaging the platform for your distro, or reporting
bugs and feature requests, or installing Haskell onto your friends'
machines.  The process for adding new tools and libraries will be
outlined in coming weeks.

The Haskell Platform would not have been possible without the hard work
of the Cabal development team, the Hackage developers and maintainers,
the individual compiler, tool and library authors who contributed to the
suite, and the distro maintainers who build and distribute the Haskell
Platform.

Thanks!

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