Re: [Haskell-cafe] implementing try for RWST ?

2007-04-16 Thread tpledger
Jeremy Shaw wrote: : | However, I think this is buggy, because changes | to 's' and 'w' will be lost if 'm' raises an | exception. : That's determined by the way you stack your monad transformers when declaring the type: adding error handling to a writer monad, or adding writing to an error

[Haskell-cafe] why can't you surround (+) in backticks and have it be infix?

2007-01-08 Thread tpledger
David House wrote: : | You can fake this: | | (-!) = ($) | (!-) = flip ($) | | foo -! liftM2 (,) !- bar | | Not perfect, but it's interesting nonetheless. | | And yes, this was a product of some #haskell | brainstorming and algorithm tennis. :) :-) Was anyone in that brainstorm

[Haskell-cafe] Great language shootout: reloaded

2006-11-13 Thread tpledger
Donald Bruce Stewart wrote: [...] While we're here we should fix: chameneos And anything else you want to take a look at. A community page has been set up to which you can submit improved entries: http://www.haskell.org/haskellwiki/Great_language_shootout [...] Well, then! I've

[Haskell-cafe] collection monads

2006-10-08 Thread tpledger
Matthias Fischmann wrote: Do you expect the contained type x to change during a sequence of monadic actions? e.g. would you ever use (=) at the type 'Permutation Int - (Int - Permutation Bool) - Permutation Bool'? no, i don't need that. but aside from the fact that data

[Haskell-cafe] collection monads

2006-10-04 Thread tpledger
Matthias Fischmann wrote: another beginners question about monads: given the type | data (Ix x) = Permutation x = Permutation [x] i wanted to define | instance Monad Permutation where | return xs = Permutation xs but of course nothing about the monad class guarantees xs to be of

[Haskell-cafe] Mission: To take args from a list... generally

2006-10-04 Thread tpledger
Joel Koerwer wrote: Let's say I want to evaluate a function of type (a-a-...-a-a), taking the arguments from a list. If know the function ahead of time, I can simply wrap it: foo a b c d = ... wrapFoo (a:b:c:d:_) = foo a b c d But, as an exercise, I challenged myself to write a function,

[Haskell-cafe] Greetings...

2006-10-01 Thread tpledger
Seth Gordon wrote: I thought I should check and see if anyone on this list has used Haskell to munge a ten-million-row database table, and if there are any particular gotchas I should watch out for. Are you sure you want to target the data directly? Another approach, that might have a

[Haskell-cafe] Re: Why is type 'b' forced to be type 'm a' and not possibly 'm a - m a'

2006-10-01 Thread tpledger
Vivian McPhail wrote: ... I need the arg a to be evaluated before it gets passed to a1 and a2. This definition does the right thing when type 'a' is a function type, because it is not a value, but with something like 'm a - (m a - m a) - m a' with Forkable (a - b) the first arg gets evaluated

[Haskell-cafe] How would you replace a field in a CSV file?

2006-10-01 Thread tpledger
Hi Pete. For such a small self-contained task, I don't think Haskell is any better than Python. Haskell would come into its own if you wanted some assurance about type safety, and/or were taking on a task large enough to warrant the use of records (and hence record update notation). Regards,

[Haskell-cafe] Re: Why is type 'b' forced to be type 'm a' and not possibly 'm a - m a'

2006-09-20 Thread tpledger
Vivian McPhail wrote: class Forkable a where fork :: String - a - a - a What I would like to be able to do is differentiate between Forkable (m a - b) and Forkable (function type - b). Have you tried this combination of instances? instance Forkable (IO a) where ... --

Re: [Haskell-cafe] Weak pointers and referential transparency???

2006-09-13 Thread tpledger
Brian Hulley wrote: [EMAIL PROTECTED] wrote: [...] My reading of the semantics (http://haskell.org/ghc/docs/latest/html/libraries/base/System-Mem-Weak.html#4) is that you can be sure the proxy *object* is gone. My problem is that I don't know what to make of the word object in the

[Haskell-cafe] Optimization problem

2006-09-13 Thread tpledger
Magnus Jonsson wrote: [...] but your example fails on infinite lists [...] take 2 $ snd $ head $ splitStreams (map (\x - (0 ,x)) [1..]) Any approach, even sieving, will struggle with infinite lists, won't it? (take 2 . snd . head . splitStreams) [(i, i) | i - [0..]] Regards, Tom

[Haskell-cafe] Weak pointers and referential transparency???

2006-09-12 Thread tpledger
Brian Hulley wrote: [...] Ref.write proxiesRef $! (weakProxy : proxies) (This is nothing to do with your main question, but the strict application looks unnecessary there. Its right hand side is already a constructor cell.) [...] In other words, if the entry for the proxy in the

[Haskell-cafe] state and exception or types again...

2006-08-28 Thread tpledger
Andrea Rossato wrote: Now I'm trying to create a statefull evaluator, with output and exception, but I'm facing a problem I seem not to be able to conceptually solve. If a computation fails in your monad, do you still want to return a value of the result type? I'd expect not, and hence

[Haskell-cafe] Variants of a recursive data structure

2006-08-07 Thread tpledger
Klaus Ostermann wrote: [...] data Exp e = Num Int | Add e e data Labelled a = L String a newtype Mu f = Mu (f (Mu f)) type SimpleExp = Mu Exp type LabelledExp = Mu Labelled Exp The SimpleExp definition works fine, but the LabeledExp definition doesn't because I would need something

[Haskell-cafe] trace function

2006-07-20 Thread tpledger
Alexander Vodomerov wrote: import Debug.Trace main = do putStrLn xxx return (trace yyy ()) putStrLn zzz only xxx and zzz is displayed. yyy is missing. Why trace is not working? Nothing uses the value of (trace yyy ()), so it is never evaluated. Try this instead, which uses the

[Haskell-cafe] REALLY simple STRef examples

2006-07-20 Thread tpledger
Chad Scherrer wrote: x = runST $ return 1 y = runST $ do {r - newSTRef 1; readSTRef r} Neither of these works in ghci x = runST (return 1) y = runST (do {r - newSTRef 1; readSTRef r}) The escaping s is something to do with rank 2 polymorphism. (Search for rank in the ghc user guide, for

[Haskell-cafe] Re: Why is there no splitBy in the list module?

2006-07-12 Thread tpledger
Jared Updike wrote: split is... unconcatIntersperse. How about separate? (split or splitBy is better but it is used all over the place in many libs) And for strings I definitely would use split :: [a] - [a] - [[a]] a lot, just like Python's split function. And words works great for

[Haskell-cafe] closures with side effects

2006-06-28 Thread tpledger
dkarapet wrote: I have been trying to understand closures in haskell and how they relate to side effects. I have been looking around but all I find are trivial examples with no side effects. Please let me know if you know of any examples. The side effects occur in the context that causes

[Haskell-cafe] Distributing monadic(?) functions across dyadic functions

2006-04-03 Thread tpledger
Nils Anders Danielsson wrote: A function like this has been suggested for the standard libraries a couple of times before. Someone suggested the name on, which I quite like: (*) `on` f = \x y - f x * f y Thanks! I always wanted to be someone. :-) Here's the link.

[Haskell] Using MonadError within other Monads

2006-01-04 Thread tpledger
(In reply to http://www.haskell.org/pipermail/haskell/2005-December/017109.html ) One of the key things about those nested monads is that *often* you don't have to write things like return $ throwError msg but can simply write throwError msg because the nest has all the features of

[Haskell-cafe] Problem with continuations and typing

2005-12-04 Thread tpledger
Jerzy Karczmarczuk wrote: : | zeros fc sc = sc 0 zeros | | fails to compile as well. *I do not ask why, I know*. | | But I would like to continue this exercice along these lines, without too much | exotism (no monads, yet...), for my students. Do you have any simple work-around? |

[Haskell-cafe] Shortening if-then-else

2005-11-27 Thread tpledger
Arjan van IJzendoorn wrote: | Is there a shorter way to write the if-then-else part below? | if (cmdType cmd) /= (CmdSitError Server) |then return $ Just seat_num |else return Nothing | | return $ if cmdType cmd /= CmdSitError Serv | then Just