[Haskell-cafe] Re: Move MonadIO to base
On Sun, 18 Apr 2010, wren ng thornton wrote: lift ma = morph (\k - join (fmap (k . return) ma)) Monad laws simplify that to lift ma = morph (\k - ma = k . return) The type of morph requires us to Church-encode things needlessly; what we mean to say is: morph (fmap return ma). Hmm. If I understand this (and your other emails) correctly, you’re saying my interface class Monad m = MonadMorphIO m where morphIO :: (forall b. (m a - IO b) - IO b) - m a should be equivalent to a simpler interface class Monad m = MonadJoinIO m where joinIO :: IO (m a) - m a via some isomorphism like morphIO f = joinIO (f return) joinIO m = morphIO (\w - m = w) I would be very happy to get the simpler interface to work, because it’s Haskell 98. However, if I write joinIO m = morphIO (\w - m = w) morphIO' f = joinIO (f return) and define catch using morphIO' instead of morphIO: m `catch` h = morphIO $ \w - w m `Control.Exception.catch` \e - w (h e) m `catch'` h = morphIO' $ \w - w m `Control.Exception.catch` \e - w (h e) then catch' fails to actually catch anything: *Main throwIO NonTermination `catch` \NonTermination - return moo moo *Main throwIO NonTermination `catch'` \NonTermination - return moo *** Exception: loop Am I doing something wrong? Anders ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Move MonadIO to base
On 04/19/10 02:15, Anders Kaseorg wrote: I would be very happy to get the simpler interface to work, because it’s Haskell 98. However, if I write joinIO m = morphIO (\w - m= w) morphIO' f = joinIO (f return) and define catch using morphIO' instead of morphIO: m `catch` h = morphIO $ \w - w m `Control.Exception.catch` \e - w (h e) m `catch'` h = morphIO' $ \w - w m `Control.Exception.catch` \e - w (h e) then catch' fails to actually catch anything: *Main throwIO NonTermination `catch` \NonTermination - return moo moo *Main throwIO NonTermination `catch'` \NonTermination - return moo *** Exception:loop Am I doing something wrong? Well, let's see what happens if we apply it to the fairly easy instance MonadMorphIO IO where morphIO f = f id then joinIO m = morphIO (\w - m = w) = (\w - m = w) (id) = m = id = join m morphIO' f = joinIO (f return) = join (f return) morphIO = f id m `catch` h = morphIO $ \w - w m `Control.Exception.catch` \e - w (h e) [w = id] = id m `Control.Exception.catch` \e - id (h e) m `catch'` h = morphIO' $ \w - w m `Control.Exception.catch` \e - w (h e) [w = return] = join (return m `Control.Exception.catch` \e - return (h e)) Do you see the difference? The effects are sequenced in different places. The return/join pair moves all the effects *outside* the operations such as catch... thus defeating the entire purpose of morphIO. -Isaac ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] iPhone/Android and Haskell [Was: Embedded funcional programming?]
liamoc: On 19 April 2010 05:29, Don Stewart d...@galois.com wrote: That's great info -- we do have an unregisterised ARM port of GHC in Debian, iirc. (And the LLVM backend can generate ARM code too) Sounds good. With regards to LLVM, what dependencies does LLVM ARM code have? Android has gnu libraries not llvm, i don't know if that is okay. A superior approach would be to compile haskell to Java or Dalvik bytecode (or even JVM bytecode if it doesn't use any JIT features; then we can compile that to dalvik bytecode), but this is obviously more work if we already have an ARM port. More work also in that you need to port the runtime system to Java... ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Data instance for a GADT
Hi Ozgur, At least template-haskell-2.4.0.0 (which comes with GHC 6.12) has syntax for type equality constraints [1], so I'm guessing it should support GADTs (I haven't actually tested it). It also has syntax for type families. Cheers, Pedro [1] http://hackage.haskell.org/packages/archive/template-haskell/2.4.0.0/doc/html/Language-Haskell-TH-Syntax.html#t%3ACxt On Wed, Apr 14, 2010 at 11:53, Ozgur Akgun ozgurak...@gmail.com wrote: Seeing this old thread[1], I hope something happened towards enabling this. Does anybody know the current status about using TH on GADTs? [1] http://www.haskell.org/pipermail/template-haskell/2006-August/000567.html On 14 April 2010 10:32, Ozgur Akgun ozgurak...@gmail.com wrote: answering to myself: I guess this is related: http://hackage.haskell.org/trac/ghc/ticket/3497 On 14 April 2010 10:13, Ozgur Akgun ozgurak...@gmail.com wrote: Cafe, How can I provide a Data instance for a GADT? I am trying to TH on it, and Uniplate requires Data. I tried StandaloneDeriving, but it seems not to work. Best, -- Ozgur Akgun -- Ozgur Akgun -- Ozgur Akgun ___ 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] Functional Dependencies conflicts
It seems like a reasonable and not-too-painful solution, thanks! Concerning Haskell typesystem, I know it to be beautiful, but also kind of complex. One of the great Haskell assets is genericity, but this complexity sometimes encumbers this genericity. But still, Haskell is -- in terms of flexibility -- way before other languages which pretend to be generic. 2010/4/18 Sebastian Fischer s...@informatik.uni-kiel.de On Apr 18, 2010, at 11:01 AM, Limestraël wrote: It's strange I can't declare a generic instance for Binary types... I thought I was trying to do something quite common in Haskell. A common workaround is to define a newtype like this newtype GenericBinary a = GB { fromGB :: a } and an instance like this instance Binary a = Binarizable (GenericBinary a) a where toBinary = fromGB which only needs FlexibleInstances enabled. You can then 'tag' Binary types for which you want to use the generic default instance above with the GB newtype constructor. Whether this is less of a pain than implementing a Binarizable instance for each Binary type is a different question.. Sebastian -- Underestimating the novelty of the future is a time-honored tradition. (D.G.) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Move MonadIO to base
On Mon, 19 Apr 2010, Isaac Dupree wrote: Do you see the difference? Yes; my question is more whether Wren has a more clever way to get an isomorphism (forall b. (m a - IO b) - IO b) - IO (m a) that would make the simpler interface work out. (Or maybe I misunderstood what he was getting at.) Anders ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] memory needed for SAX parsing XML
Hello haskellers! I'm trying to process an xml file with as little footprint as possible. SAX is alright for my case, and I think that's the lightest way possible. So, I'm looking at HaXml.SAX I'm surprised to see that it takes about 56-60 MB of ram. This seems constant relative to xml file size, which is expected. Only slightly depends on it as I recursively traverse the list of sax events. But it seems like too much. The size of the file is from 1MB to 20MB. The code is something like this main = do (fn:_) - getArgs h - openFile fn ReadMode c - hGetContents h let out = proc $ fst $ saxParse fn c putStrLn out getChar -- 'f' is tail-recursive -- 'i' is used only to ensure that the list is completely traversed proc es = show $ f es 0 where f :: [SaxElement] - Int - Int f (SaxElementOpen name _ : rest) i = f rest i f (_ : rest) i = f rest i f [] i = i Thanks for you thoughts! -- Daniil Elovkov ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: hamming distance allocation
Arnoldo Muller wrote: I want to generate some hamming distance statistics about a set of strings. filter (\x - x /= 0) $ map (uncurry hammingX) [(xs, ys) | xs - exampl, ys - exampl] [...] -- function posted in this mailing list hamming2 :: String - String - Int hamming2 xs ys = length (filter not (zipWith (==) xs ys)) I am executing these functions millions of times and the bottleneck of my program is in them as explained by running in profiling mode with +RTS -K400M -p -RTS The costlier function is the hamming distance COST CENTREMODULE %time %alloc hammingDistances 66.6 41.9 Another way to look at it is that you shouldn't optimize hamming itself, but rather make sure that it's called less often! For instance, your expression can be replaced by filter (/=0) [hammingX x y | (x:xs) - tails example, y - xs] which cuts the total running time in half. It's still quadratic in the length of example . I'm sure there are faster algorithms out there that can bring it down to O(n log n) if you want. Regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: hamming distance allocation
Am Montag 19 April 2010 14:13:53 schrieb Heinrich Apfelmus: Arnoldo Muller wrote: I want to generate some hamming distance statistics about a set of strings. filter (\x - x /= 0) $ map (uncurry hammingX) [(xs, ys) | xs - exampl, ys - exampl] [...] -- function posted in this mailing list hamming2 :: String - String - Int hamming2 xs ys = length (filter not (zipWith (==) xs ys)) I am executing these functions millions of times and the bottleneck of my program is in them as explained by running in profiling mode with +RTS -K400M -p -RTS The costlier function is the hamming distance COST CENTREMODULE %time %alloc hammingDistances 66.6 41.9 Another way to look at it is that you shouldn't optimize hamming itself, but rather make sure that it's called less often! For instance, your expression can be replaced by filter (/=0) [hammingX x y | (x:xs) - tails example, y - xs] which cuts the total running time in half. It's still quadratic in the length of example . I'm sure there are faster algorithms out there that If it's likely that there are many repetitions, collect the Strings in a Set/Map (depending on whether you're interested in the count) and call hamming only on the distinct pairs. can bring it down to O(n log n) if you want. I don't think so. You can't calculate the Hamming distance of x and z from the distances between x and y and y and z, so you'd have to consider all pairs of distinct strings, wouldn't you? Regards, Heinrich Apfelmus ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] hamming distance allocation
Subject: Re: [Haskell-cafe] hamming distance allocation Am Montag 19 April 2010 01:03:14 schrieb Arnoldo Muller: Hello all: I want to generate some hamming distance statistics about a set of strings. As explained in another e-mail in this list, I used the following code to call the functions: (exampl holds the list of strings of size w) filter (\x - x /= 0) $ map (uncurry hammingX) [(xs, ys) | xs - exampl, ys - exampl] I have two hamming functions: -- hamming distance for variable length strings hamming :: String - String - Int hamming x y = hamming' x y 0 where hamming' [] _ !c = c hamming' _ [] !c = c hamming' (x:xs) (y:ys) !c | x == y = hamming' xs ys c | otherwise = hamming' xs ys (c + 1) -- function posted in this mailing list hamming2 :: String - String - Int hamming2 xs ys = length (filter not (zipWith (==) xs ys)) I am executing these functions millions of times and the bottleneck of my program is in them as explained by running in profiling mode with +RTS -K400M -p -RTS The costlier function is the hamming distance COST CENTRE MODULE %time %alloc hamming Distances 66.6 41.9 It says that it is performing 41% of the allocations. In the case of hamming2 the allocations go as far as 52%. Allocations are cheap, so that's not necessarily a problem. More important is, what's the maximum residency and how much is copied during GC? Are you compiling with -O2 ? I could understand that there are allocations in hamming2 because we are creating pairs, but in the case of hamming there should be no allocation. Why not? I don't know how GHC counts allocations, but everytime you go from (x:xs) to xs, you need a new pointer to the tail. If that counts as allocation, hamming must allocate a lot, too. Is it really necessary to use Strings? I think a packed type, e.g. Vector or ByteString, would be much more efficient here. Of course this is only likely to be a benefit if you can move away from String entirely. I suspect that hamming2 would perform better then. John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Patch to add process group support
For future reference, the procedure for changes like this is to follow the Library Submissions guidelines at http://www.haskell.org/haskellwiki/Library_submissions. In this case you've already made a patch and a detailed proposal, so I don't see any reason why we shouldn't consider it anyway. My thoughts on the changes: - yes to adding new_group to the CreateProcess record, and corresponding support to System.Process.Internals - no to adding runCommandNewGroup, and the other *NewGroup functions. These were kept mostly for backwards compatibility anyway, the new API is createProcess, shell, proc, readProcess. I don't think people need new_group often enough to provide canned variants of runCommand etc. for it. Cheers, Simon On 17/04/2010 16:26, Hamish Mackenzie wrote: The attached patch for the process package adds support for creating and interrupting process groups on Unix and Win32 systems. Currently we have to use a nasty hack in Leksah that only works on Unix systems (and even then not very well). On Win32 Leksah's background build feature is dreadful as a results (because it has no way to interrupt the build and start over when the user makes more changes). I would love to get this onto Hackage somehow, if not as a new version of the process package, perhaps as an alternative package (process-groups using System.Process.Groups instead of System.Process). Please can you have a look and let me know what you think? Thanks, Hamish This patch introduces the following functions to System.Process * runCommandNewGroup, runProcessNewGroup, runInteractiveCommandNewGroup and runInteractiveProcessNewGroup __ These are variations on the existing functions for running processes. They create the child process as the lead process in a new process group. Unix - calls setpgid in both the parent and the child process after fork. Win32 - calls CreateProcess with the CREATE_NEW_PROCESS_GROUP set. I also had it unset CREATE_NO_WINDOW because this seems to prevent the child attaching to the parents console (and therefor stops interuptProcessGroup from working). * interruptProcessGroup This function can be used interrupt a running process group. Unix - calls signalProcessGroup to send sigINT Win32 - If the process ID is known it calls generateConsoleCtrlEvent to send cTRL_BREAK_EVENT __ Compatibility __ Backward Compatibility CreateProcess has a new field new_group which may need to be added to some existing code. If set to False the current behaviour is preserved. As far as I know this is the only change that could break existing code. Linker Errors I have renamed the C functions it used in order to prevent linker errors when using this new version with the existing process package. __ Win32 Only __ On Win32 the process handle is not the same as the process ID and there is no reliable way to convert from one to the other. I have added an interface that allows access to the process ID, but does not change the behaviour of the existing functions. * PINFO Replaces PHANDLE in the ProcessHandle type. type PINFO = (PHANDLE, Maybe Word32) -- Handle and Process ID * mkProcessHandleWithPID Like mkProcessHandle but allows you to specify the processes ID as well. This function is now used in all the run functions so the ProcessHandle they return will contain a process ID. * withProcessInfo and withProcessInfo_ Like withProcessHandle functions but gives you access to the PINFO (not just the PHANDLE it contains). ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Fwd: Re: Simple game: a monad for each player
Heinrich Apfelmus wrote: Limestraël wrote: Okay, I start to understand better... Just, Heinrich, how would implement the mapMonad function in terms of the operational package? You just shown the signature. Ah, that has to be implemented by the library, the user cannot implement this. Internally, the code would be as Bertram suggests: mapMonad :: (Monad m1, Monad m2) = (forall a . m1 a - m2 a) - ProgramT instr m1 a - ProgramT instr m2 a mapMonad f (Lift m1) = Lift (f m1) mapMonad f (Bind m k) = Bind (mapMonad f m) (mapMonad f . k) mapMonad f (Instr i) = Instr i Silly me! This can be implement by the user: mapMonad f = id' = lift . f . viewT where id' :: ProgramViewT instr m1 a - ProgramT instr m2 a id' (Return a) = return a id' (i := k) = singleton i = mapMonad f . k and it would be a shame for the operational approach if that were not possible. :) Regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] hamming distance allocation
Am Montag 19 April 2010 14:37:33 schrieb John Lato: Is it really necessary to use Strings? I think a packed type, e.g. Vector or ByteString, would be much more efficient here. Not very much if the strings are fairly short (and the list isn't too long, so there's not a big difference in cache-friendliness). If eight-bit characters aren't enough, packing the strings into UArray Int Char gives performance quite close to ByteStrings. Of course this is only likely to be a benefit if you can move away from String entirely. I suspect that hamming2 would perform better then. John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ANN: scan-0.1.0.3, a Haskell style scanner
Dear Haskell friends, I like to announce a Haskell style scanner at http://hackage.haskell.org/package/scan documented under http://projects.haskell.org/style-scanner/ It's best used in conjunction with hlint http://community.haskell.org/~ndm/hlint/ and gives many suggestions regarding the file format. Feedback is welcome. Thanks Christian (Discussions should only be posted to either haskell-cafe@ or beginners@) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] hamming distance allocation
From: Daniel Fischer daniel.is.fisc...@web.de Am Montag 19 April 2010 14:37:33 schrieb John Lato: Is it really necessary to use Strings? I think a packed type, e.g. Vector or ByteString, would be much more efficient here. Not very much if the strings are fairly short (and the list isn't too long, so there's not a big difference in cache-friendliness). If eight-bit characters aren't enough, packing the strings into UArray Int Char gives performance quite close to ByteStrings. I agree, provided that the Strings are used only once. I missed the first part of this thread, so there may be context I don't have, but if Strings are retained and the Hamming distance calculated for multiple pairings, I think it would be a noticeable difference. Although probably not as much as reducing the number of calls to Hamming as you and H. Apfelmus suggest. John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] hamming distance allocation
Hello John: Well I could use a packed type. The only letters that will be found in the string are ATCG so yeah I don't need unicode and those things. Will try out with vector or ByteString. Thanks! :) On Mon, Apr 19, 2010 at 2:37 PM, John Lato jwl...@gmail.com wrote: Subject: Re: [Haskell-cafe] hamming distance allocation Am Montag 19 April 2010 01:03:14 schrieb Arnoldo Muller: Hello all: I want to generate some hamming distance statistics about a set of strings. As explained in another e-mail in this list, I used the following code to call the functions: (exampl holds the list of strings of size w) filter (\x - x /= 0) $ map (uncurry hammingX) [(xs, ys) | xs - exampl, ys - exampl] I have two hamming functions: -- hamming distance for variable length strings hamming :: String - String - Int hamming x y = hamming' x y 0 where hamming' [] _ !c = c hamming' _ [] !c = c hamming' (x:xs) (y:ys) !c | x == y = hamming' xs ys c | otherwise = hamming' xs ys (c + 1) -- function posted in this mailing list hamming2 :: String - String - Int hamming2 xs ys = length (filter not (zipWith (==) xs ys)) I am executing these functions millions of times and the bottleneck of my program is in them as explained by running in profiling mode with +RTS -K400M -p -RTS The costlier function is the hamming distance COST CENTREMODULE %time %alloc hammingDistances 66.6 41.9 It says that it is performing 41% of the allocations. In the case of hamming2 the allocations go as far as 52%. Allocations are cheap, so that's not necessarily a problem. More important is, what's the maximum residency and how much is copied during GC? Are you compiling with -O2 ? I could understand that there are allocations in hamming2 because we are creating pairs, but in the case of hamming there should be no allocation. Why not? I don't know how GHC counts allocations, but everytime you go from (x:xs) to xs, you need a new pointer to the tail. If that counts as allocation, hamming must allocate a lot, too. Is it really necessary to use Strings? I think a packed type, e.g. Vector or ByteString, would be much more efficient here. Of course this is only likely to be a benefit if you can move away from String entirely. I suspect that hamming2 would perform better then. John ___ 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] hamming distance allocation
The strings will not be longer than 30 characters. I am doing sets of 2000 (total of 2000^2 distance computations) I am expecting that all the operations will be lazyly performed but at some point I get a memory error. Most of the memory is being allocated for the hamming distance and I am still unable to find the source of my memory leak. Regards, Arnoldo On Mon, Apr 19, 2010 at 3:47 PM, Daniel Fischer daniel.is.fisc...@web.dewrote: Am Montag 19 April 2010 14:37:33 schrieb John Lato: Is it really necessary to use Strings? I think a packed type, e.g. Vector or ByteString, would be much more efficient here. Not very much if the strings are fairly short (and the list isn't too long, so there's not a big difference in cache-friendliness). If eight-bit characters aren't enough, packing the strings into UArray Int Char gives performance quite close to ByteStrings. Of course this is only likely to be a benefit if you can move away from String entirely. I suspect that hamming2 would perform better then. John ___ 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: [Haskell] ANN: scan-0.1.0.3, a Haskell style scanner
Hello Christian, On Apr 19, 2010, at 4:48 PM, Christian Maeder wrote: I like to announce a Haskell style scanner at http://hackage.haskell.org/package/scan Feedback is welcome. I get lots of multiple blanks which I'd rather not correct. I often use multiple blanks to achieve vertical layout which is especially useful in combination with lhs2TeX [1] whose polycode mode requires multiple blanks to achieve proper indentation. This code instance Eq a = Eq (Maybe a) where Nothing == Nothing = True Just x == Just y = x == y _== _= False triggers this scan output: scan-test.hs:2:10: up to column 12 multiple (2) blanks scan-test.hs:2:14: up to column 16 multiple (2) blanks scan-test.hs:2:23: up to column 25 multiple (2) blanks scan-test.hs:3:9: up to column 12 multiple (3) blanks scan-test.hs:3:14: up to column 16 multiple (2) blanks scan-test.hs:3:22: up to column 25 multiple (3) blanks scan-test.hs:4:4: up to column 12 multiple (8) blanks scan-test.hs:4:14: up to column 16 multiple (2) blanks scan-test.hs:4:17: up to column 25 multiple (8) blanks I very much prefer the previous indentation over the following version stripped down by scan - (using the hyphen option): instance Eq a = Eq (Maybe a) where Nothing == Nothing = True Just x == Just y = x == y _ == _ = False I did not find a way to configure scan to ignore multiple blanks. Did I miss it? Sebastian [1]: http://people.cs.uu.nl/andres/lhs2tex/ -- Underestimating the novelty of the future is a time-honored tradition. (D.G.) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Asynchronous exception wormholes kill modularity
On 10/04/2010 20:07, Iavor Diatchki wrote: Hello, I wonder if it might be possible to use just one primitive which atomically changes the interrupt mask for a thread? Here is an example of what I'm thinking: data MaskingState = Unmasked | MaskedInterruptible | MaskedNonInterruptible -- Atomically changes the interrupt mask for a thread, and returns the old mask. setMask:: MaskingState - IO MaskingState setMask = error primitive? -- Change the mask for the duration of an IO action. -- The action is passed the old mask. scopedSetMask :: MaskingState - (MaskingState - IO a) - IO a scopedSetMask m io = do m1 - setMask m a - io m1 setMask m1 return a -- Change the mask for the duration of an IO action. scopedSetMask_ :: MaskingState - IO a - IO a scopedSetMask_ m io = scopedSetMask m $ \_ - io -- Simon's mask: mask :: ((IO a - IO a) - IO b) - IO b mask f = scopedSetMask MaskedInterruptible $ \m - f (scopedSetMask_ m) I could replace 3 of the primitives I have (block, unblock, and uninterruptibleBlock) with just one as you suggest, yes. And we could replace the scoping behaviour of the primitives with scopedSetMask, although some care would be needed to make sure it wasn't any less efficient, we would probably have to explicitly expand the code for scopedSetMask into the three possible cases. However, the current block and unblock primitives have a bit of clever logic to keep the stack at a constant size when called recursively (see the async exceptions paper for details), we would lose that if we used the above formulation. Note that this isn't the only place that changes the masking state: when an exception is raised, we have to temporarily mask exeptions for the handler, and then restore them to the prevailing state if the handler returns. The way the primitives are currently defined makes this quite easy, because I have ready-made stack frames to use. We could lift this into Haskell by redefining catch: catch :: IO a - (Exception - IO a) - IO a catch io handler = mask $ \restore - restore io `realCatch` handler but this adds more overhead to catch, and the implementation of throw still has to restore the masking state from the stack frame for catch. BTW, you also need a way to check what the current masking state is, otherwise the wormhole that was the original problem being discussed here reappears. For example, mask should only change the masking state to MaskedInterruptible if it is currently Unmasked, otherwise it will (a) make the state interruptible if it was uninterruptible, and (b) introduce an unnecessary stack frame. Cheers, Simon -Iavor On Sat, Apr 10, 2010 at 11:42 AM, Iavor Diatchki iavor.diatc...@gmail.com mailto:iavor.diatc...@gmail.com wrote: Hello, It seems that rank-2 types are sufficient to make the more polymorphic types: {-# LANGUAGE Rank2Types #-} import Control.Exception data Mask = Mask (forall a. IO a - IO a) mask :: (Mask - IO a) - IO a mask io = do b - blocked if b then io (Mask id) else block $ io (Mask unblock) restore :: Mask - IO a - IO a restore (Mask f) a = f a -- This is useful in an example like this: forkThen :: IO () - IO a - IO a forkThen io k = mask $ \m - do tid - forkIO (restore m io) restore m k `catch` \e - do when (e == ThreadKilled) (killThread tid) throwIO e -Iavor On Thu, Apr 8, 2010 at 1:23 AM, Simon Marlow marlo...@gmail.com mailto:marlo...@gmail.com wrote: On 07/04/2010 18:54, Isaac Dupree wrote: On 04/07/10 11:12, Simon Marlow wrote: It's possible to mis-use the API, e.g. getUnmask = mask return ...incidentally, unmask a = mask (\restore - return restore) = (\restore - restore a) That doesn't work, as in it can't be used to unmask exceptions when they are masked. The 'restore' you get just restores the state to its current, i.e. masked, state. mask :: ((IO a - IO a) - IO b) - IO b It needs to be :: ((forall a. IO a - IO a) - IO b) - IO b so that you can use 'restore' on two different pieces of IO if you need to. (alas, this requires not just Rank2Types but RankNTypes. Also, it doesn't cure the loophole. But I think it's still essential.) Sigh, yes I suppose that's true, but I've never encountered a case where I needed to call unmask more than once, let alone at different types, within the scope of a mask. Anyone else? Cheers, Simon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org mailto:Haskell-Cafe@haskell.org
Re: [Haskell-cafe] ANN: scan-0.1.0.3, a Haskell style scanner
On Mon, 19 Apr 2010, Christian Maeder wrote: Dear Haskell friends, I like to announce a Haskell style scanner at http://hackage.haskell.org/package/scan At first I thought it is a scanner (for whatever purpose) implemented in Haskell style. No it checks whether a Haskell module follows a certain style. - Nice idea and nice implementation! documented under http://projects.haskell.org/style-scanner/ The updated Haskell code might be written to a new file by default. Then I can interactively transfer the corrections I like to the original code using Kompare. I would also not use '-' as option. How would you extend the set of options later, say for de-/selection of specific warnings? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] hamming distance allocation
Hello Daniel: My % GC time is : 75.0% (81.4% elapsed) and I am compiling with -O2. Thank you for clarifying about the pointers. Slowly my memory grows up and eventually it explodes. I would expect that the list comprehension is lazily evaluated and therefore at any given time I am only executing one hamming distance. The result of the hamming distance is stored into a small statistics datatype I built (only stores sums and sum of squares and the counts). This datatype is updated using a foldr. I have no idea where the leak is. What do you see in a .prof file to find a leak (hamming distance has the largest amount of time and %alloc) ? From my .prof file where would you start looking at? Best Regards, Arnoldo Muller On Mon, Apr 19, 2010 at 3:18 AM, Daniel Fischer daniel.is.fisc...@web.dewrote: Am Montag 19 April 2010 01:03:14 schrieb Arnoldo Muller: Hello all: I want to generate some hamming distance statistics about a set of strings. As explained in another e-mail in this list, I used the following code to call the functions: (exampl holds the list of strings of size w) filter (\x - x /= 0) $ map (uncurry hammingX) [(xs, ys) | xs - exampl, ys - exampl] I have two hamming functions: -- hamming distance for variable length strings hamming :: String - String - Int hamming x y = hamming' x y 0 where hamming' [] _ !c = c hamming' _ [] !c = c hamming' (x:xs) (y:ys) !c | x == y = hamming' xs ys c | otherwise = hamming' xs ys (c + 1) -- function posted in this mailing list hamming2 :: String - String - Int hamming2 xs ys = length (filter not (zipWith (==) xs ys)) I am executing these functions millions of times and the bottleneck of my program is in them as explained by running in profiling mode with +RTS -K400M -p -RTS The costlier function is the hamming distance COST CENTREMODULE %time %alloc hammingDistances 66.6 41.9 It says that it is performing 41% of the allocations. In the case of hamming2 the allocations go as far as 52%. Allocations are cheap, so that's not necessarily a problem. More important is, what's the maximum residency and how much is copied during GC? Are you compiling with -O2 ? I could understand that there are allocations in hamming2 because we are creating pairs, but in the case of hamming there should be no allocation. Why not? I don't know how GHC counts allocations, but everytime you go from (x:xs) to xs, you need a new pointer to the tail. If that counts as allocation, hamming must allocate a lot, too. How can I execute my hamming functions without allocating memory? Best regards, Arnoldo Muller jasparReader.prof Description: Binary data ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: [Haskell] ANN: scan-0.1.0.3, a Haskell style scanner
Sebastian Fischer schrieb: Hello Christian, On Apr 19, 2010, at 4:48 PM, Christian Maeder wrote: I like to announce a Haskell style scanner at http://hackage.haskell.org/package/scan Feedback is welcome. I get lots of multiple blanks which I'd rather not correct. I often use multiple blanks to achieve vertical layout which is especially useful in combination with lhs2TeX [1] whose polycode mode requires multiple blanks to achieve proper indentation. This code instance Eq a = Eq (Maybe a) where Nothing == Nothing = True Just x == Just y = x == y _== _= False This sort of tabular layout is not supported by scan. triggers this scan output: scan-test.hs:2:10: up to column 12 multiple (2) blanks scan-test.hs:2:14: up to column 16 multiple (2) blanks scan-test.hs:2:23: up to column 25 multiple (2) blanks scan-test.hs:3:9: up to column 12 multiple (3) blanks scan-test.hs:3:14: up to column 16 multiple (2) blanks scan-test.hs:3:22: up to column 25 multiple (3) blanks scan-test.hs:4:4: up to column 12 multiple (8) blanks scan-test.hs:4:14: up to column 16 multiple (2) blanks scan-test.hs:4:17: up to column 25 multiple (8) blanks At least you see a regular pattern wrt column position: (12, 16, 25) I very much prefer the previous indentation over the following version stripped down by scan - (using the hyphen option): instance Eq a = Eq (Maybe a) where Nothing == Nothing = True Just x == Just y = x == y _ == _ = False I did not find a way to configure scan to ignore multiple blanks. Did I miss it? It isn't yet implemented. Cheers Christian Sebastian [1]: http://people.cs.uu.nl/andres/lhs2tex/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] newbie question how to pass data
Hello I am sorry for the silly question. I have a function as the following func:: ((Float,Float) -Bool) - Float - ((Float,Float) - Bool) I am trying to make calculation in this type ((Float,Float) -Bool) with Float and then pass the information to ((Float,Float) - Bool) Thank again appreciated. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Asynchronous exception wormholes kill modularity
On 10/04/2010 19:42, Iavor Diatchki wrote: Hello, It seems that rank-2 types are sufficient to make the more polymorphic types: {-# LANGUAGE Rank2Types #-} import Control.Exception data Mask = Mask (forall a. IO a - IO a) mask :: (Mask - IO a) - IO a mask io = do b- blocked if b then io (Mask id) else block $ io (Mask unblock) restore :: Mask - IO a - IO a restore (Mask f) a = f a -- If you're going to do that, you could even get rid of the Rank 2 type completely: data Mask = RestoreUnmask | RestoreMaskInterruptible | .. restore RestoreUnmask a = unblock a restore RestoreMaskInterruptible a = block a ... at the expense of a little run-time tag testing. But that's up to the implementation of course; the Mask type can be abstract. So I think I like this variant, even though it adds a little API overhead. Anyone else have any thoughts on this? Cheers, Simon This is useful in an example like this: forkThen :: IO () - IO a - IO a forkThen io k = mask $ \m - do tid- forkIO (restore m io) restore m k `catch` \e - do when (e == ThreadKilled) (killThread tid) throwIO e -Iavor On Thu, Apr 8, 2010 at 1:23 AM, Simon Marlowmarlo...@gmail.com wrote: On 07/04/2010 18:54, Isaac Dupree wrote: On 04/07/10 11:12, Simon Marlow wrote: It's possible to mis-use the API, e.g. getUnmask = mask return ...incidentally, unmask a = mask (\restore - return restore)= (\restore - restore a) That doesn't work, as in it can't be used to unmask exceptions when they are masked. The 'restore' you get just restores the state to its current, i.e. masked, state. mask :: ((IO a - IO a) - IO b) - IO b It needs to be :: ((forall a. IO a - IO a) - IO b) - IO b so that you can use 'restore' on two different pieces of IO if you need to. (alas, this requires not just Rank2Types but RankNTypes. Also, it doesn't cure the loophole. But I think it's still essential.) Sigh, yes I suppose that's true, but I've never encountered a case where I needed to call unmask more than once, let alone at different types, within the scope of a mask. Anyone else? Cheers, Simon ___ 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] Re: [Haskell] ANN: scan-0.1.0.3, a Haskell style scanner
I wrote: I did not find a way to configure scan to ignore multiple blanks. The poor man's solution is to pipe the output through grep --invert-match --regexp=multiple ([0-9]*) blanks I agree with Henning about the hyphen option. This often (usually?) means don't read from a file but from stdin. Sebastian -- Underestimating the novelty of the future is a time-honored tradition. (D.G.) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: scan-0.1.0.3, a Haskell style scanner
Henning Thielemann schrieb: On Mon, 19 Apr 2010, Christian Maeder wrote: Dear Haskell friends, I like to announce a Haskell style scanner at http://hackage.haskell.org/package/scan At first I thought it is a scanner (for whatever purpose) implemented in Haskell style. No it checks whether a Haskell module follows a certain style. - Nice idea and nice implementation! documented under http://projects.haskell.org/style-scanner/ The updated Haskell code might be written to a new file by default. Then I can interactively transfer the corrections I like to the original code using Kompare. I would also not use '-' as option. How would you extend the set of options later, say for de-/selection of specific warnings? I don't know (and have) Kompare, thanks for mentioning it. Currently '-' is the only option and I expect other options to be different from it, like -l or -i. (But maybe I'll change it or add a -o option.) Christian ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] memory needed for SAX parsing XML
On Mon, Apr 19, 2010 at 3:01 AM, Daniil Elovkov daniil.elov...@googlemail.com wrote: Hello haskellers! I'm trying to process an xml file with as little footprint as possible. SAX is alright for my case, and I think that's the lightest way possible. So, I'm looking at HaXml.SAX I'm surprised to see that it takes about 56-60 MB of ram. This seems constant relative to xml file size, which is expected. Only slightly depends on it as I recursively traverse the list of sax events. But it seems like too much. For me these sorts of problems always involve investigation into the root cause. I'm just not good enough at predicting what is causing the memory consumption. Thankfully, GHC has great tools for this sort of investigative work. The book real-world haskell documents how to use those tools: http://book.realworldhaskell.org/read/profiling-and-optimization.html If you haven't already, I highly recommend looking at the profiling graphs. See if you can figure out if your program has any space leaks. The size of the file is from 1MB to 20MB. The code is something like this main = do (fn:_) - getArgs h - openFile fn ReadMode c - hGetContents h let out = proc $ fst $ saxParse fn c putStrLn out getChar For such a simple program you won't run into any problem with lazy IO, but as your program grows in complexity it will very likely come back to bite you. If you're not familiar with lazy IO, I'm referring to the hGetContents. Some example problems: 1) If you opened many files this way, you could run out of file handles (lazy IO closing of handles is unpredictable, but file handles are a scarce resource). The safe-io package on hackage can help you avoid this particular pitfall. 2) Reading of the file will happen during your pure code. This implies that IO exceptions can happen in your pure code. It also means that in some ways you'll be able to observe side-effects in your pure code. 3) If you were to reference 'c' from two places in main, the GC would not collect any of it until both references were collectable. To avoid that leak, you'd need to load the data twice to avoid the memory leak. I'm sure there are other things that can go wrong that i've missed. I think iteratees are slowly catching on as an alternative to lazy io. Basically, the iteratee approach uses a left fold style to stream the data and process it in chunks, including some exception handling. Unfortunately, I think it may also require a special sax parser that is specifically geared towards iteratee use. Having an iteratee based sax parser would make processing large xml streams very convenient in haskell. Hint, hint, if you want to write a library :) (Or, maybe it exists, I admit that I haven't checked.) I hope that helps, Jason ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Patch to add process group support
On 20 Apr 2010, at 00:57, Simon Marlow wrote: My thoughts on the changes: - yes to adding new_group to the CreateProcess record, and corresponding support to System.Process.Internals - no to adding runCommandNewGroup, and the other *NewGroup functions. These were kept mostly for backwards compatibility anyway, the new API is createProcess, shell, proc, readProcess. I don't think people need new_group often enough to provide canned variants of runCommand etc. for it. I have revised the patch and the description accordingly and submitted it here... http://hackage.haskell.org/trac/ghc/ticket/3994 Hamish ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: help with Haskell programming
On Sun, Apr 18, 2010 at 10:25 AM, Sean Leather leat...@cs.uu.nl wrote: This is the annoying part about Haskell . I can not understand composition . One of the ways of understanding composition (and many other functions in Haskell) is by trying to understand its type. Here it is shown by looking at the type in the interpreter GHCi. *Main :t (.) (.) :: (b - c) - (a - b) - a - c It's a function that takes three arguments, the first two of which are functions, and the third is something else. As you mention below the function arrow (-), is right associative. For this reason I like to think of the above function as binary, instead of a function of 3 arguments. Making the associativity explicit we can rewrite it: (.) :: (b - c) - (a - b) - (a - c) Now we can see that it is a binary function on functions. You're mileage may vary, but I find this form more intuitive. Jason ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: scan-0.1.0.3, a Haskell style scanner
Christian Maeder schrieb: Henning Thielemann schrieb: The updated Haskell code might be written to a new file by default. Then I can interactively transfer the corrections I like to the original code using Kompare. I would also not use '-' as option. How would you extend the set of options later, say for de-/selection of specific warnings? I don't know (and have) Kompare, thanks for mentioning it. It's part of KDE. There is also TkDiff, but I don't know whether it supports moving around changes. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Strange error with type classes + associated types
On Sun, Apr 18, 2010 at 9:02 PM, Brent Yorgey byor...@seas.upenn.eduwrote: Conal, Thanks for looking into this! Making (:-*) into a proper type seems promising. I did try wrapping (:-*) in a newtype but that didn't help (although I didn't expect it to). What do you mean by a proper type? I didn't know what Roman meant either, though I guessed he meant a newtype or data type. I see you just uploaded a new version of vector-space; what's new in 0.6.2? The dependency on the Boolean package now specifies = 0.0.1. -Brent On Sat, Apr 17, 2010 at 10:28:45AM -0700, Conal Elliott wrote: Oh! I'd completely forgotten about this idea. Looking at Data.LinearMap in vector-space, I see a comment about exactly this ambiguity, as well as the start of a new module that wraps a data type around the linear map representation. I don't recall whether I got stuck or just distracted. On Sat, Apr 17, 2010 at 3:46 AM, Roman Leshchinskiy r...@cse.unsw.edu.au wrote: On 17/04/2010, at 11:00, Conal Elliott wrote: I'm unsure now, but I think I tried making Basis a data type (not syn) and ran into the problem I mentioned above. The Basis *synonyms* also have HasTrie instances, which is crucially important. If we switch to (injective) data types, then we lose the HasTrie instances. I'd be okay with defining HasTrie instances (preferably via deriving) for the associated Basis data types, but I couldn't figure out how to. Maybe it's not possible currently, or maybe I just didn't know how. Could you perhaps make (:-*) a proper type rather than a synonym? That would help with the ambiguity. Roman ___ 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] newbie question how to pass data
Can you at least give an example of how you intend to use this func? Since you do not describe it's behaviour, it is very hard to make a useful comment (at least for me) Best, On 19 April 2010 16:54, Mujtaba Boori mujtaba.bo...@gmail.com wrote: Hello I am sorry for the silly question. I have a function as the following func:: ((Float,Float) -Bool) - Float - ((Float,Float) - Bool) I am trying to make calculation in this type ((Float,Float) -Bool) with Float and then pass the information to ((Float,Float) - Bool) Thank again appreciated. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Ozgur Akgun ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] newbie question how to pass data
sorry ok I am trying to make these calculation func (x,y) s dg =((x*(cos dg) - y*(sin dg)),(x*(sin dg) - y*(cos dg))) This work for type (Float - Float) but how can make it work with ((Float - Float) - Bool) because my main function that I want use with. it takes (Float,Float) -Bool) I need to return the same type ((Float,Float) -Bool) so it could be used with other function. On Mon, Apr 19, 2010 at 5:54 PM, Ozgur Akgun ozgurak...@gmail.com wrote: Can you at least give an example of how you intend to use this func? Since you do not describe it's behaviour, it is very hard to make a useful comment (at least for me) Best, On 19 April 2010 16:54, Mujtaba Boori mujtaba.bo...@gmail.com wrote: Hello I am sorry for the silly question. I have a function as the following func:: ((Float,Float) -Bool) - Float - ((Float,Float) - Bool) I am trying to make calculation in this type ((Float,Float) -Bool) with Float and then pass the information to ((Float,Float) - Bool) Thank again appreciated. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Ozgur Akgun -- Mujtaba Ali Alboori ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] hamming distance allocation
Hello all: I found my leak after adding some bang patterns in a different part of the program. The compiler was generating all the combinations of the list comprehensions and therefore the performance dropped very badly. BTW, hamming is 2 times faster than hamming2. Thank you as always! Arnoldo On Mon, Apr 19, 2010 at 5:53 PM, Arnoldo Muller arnoldomul...@gmail.comwrote: Hello Daniel: My % GC time is : 75.0% (81.4% elapsed) and I am compiling with -O2. Thank you for clarifying about the pointers. Slowly my memory grows up and eventually it explodes. I would expect that the list comprehension is lazily evaluated and therefore at any given time I am only executing one hamming distance. The result of the hamming distance is stored into a small statistics datatype I built (only stores sums and sum of squares and the counts). This datatype is updated using a foldr. I have no idea where the leak is. What do you see in a .prof file to find a leak (hamming distance has the largest amount of time and %alloc) ? From my .prof file where would you start looking at? Best Regards, Arnoldo Muller On Mon, Apr 19, 2010 at 3:18 AM, Daniel Fischer daniel.is.fisc...@web.dewrote: Am Montag 19 April 2010 01:03:14 schrieb Arnoldo Muller: Hello all: I want to generate some hamming distance statistics about a set of strings. As explained in another e-mail in this list, I used the following code to call the functions: (exampl holds the list of strings of size w) filter (\x - x /= 0) $ map (uncurry hammingX) [(xs, ys) | xs - exampl, ys - exampl] I have two hamming functions: -- hamming distance for variable length strings hamming :: String - String - Int hamming x y = hamming' x y 0 where hamming' [] _ !c = c hamming' _ [] !c = c hamming' (x:xs) (y:ys) !c | x == y = hamming' xs ys c | otherwise = hamming' xs ys (c + 1) -- function posted in this mailing list hamming2 :: String - String - Int hamming2 xs ys = length (filter not (zipWith (==) xs ys)) I am executing these functions millions of times and the bottleneck of my program is in them as explained by running in profiling mode with +RTS -K400M -p -RTS The costlier function is the hamming distance COST CENTREMODULE %time %alloc hammingDistances 66.6 41.9 It says that it is performing 41% of the allocations. In the case of hamming2 the allocations go as far as 52%. Allocations are cheap, so that's not necessarily a problem. More important is, what's the maximum residency and how much is copied during GC? Are you compiling with -O2 ? I could understand that there are allocations in hamming2 because we are creating pairs, but in the case of hamming there should be no allocation. Why not? I don't know how GHC counts allocations, but everytime you go from (x:xs) to xs, you need a new pointer to the tail. If that counts as allocation, hamming must allocate a lot, too. How can I execute my hamming functions without allocating memory? Best regards, Arnoldo Muller ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] hamming distance allocation
Am Montag 19 April 2010 17:17:11 schrieb Arnoldo Muller: The strings will not be longer than 30 characters. For 20 -30 character strings, using ByteStrings should be better, in my tests about 40% faster, allocation figures slightly lower, resident memory much lower and bytes copied during GC very much lower. For a sample of english text (many short words, few long), ByteStrings were about 25% faster, allocation figures very slightly lower, resident memory much lower, bytes copied much lower (relative difference not as large as for longer strings). I am doing sets of 2000 (total of 2000^2 distance computations) That shouldn't give memory problems either way. I am expecting that all the operations will be lazyly performed but at some point I get a memory error. My guess is a bad consumption pattern. Most of the memory is being allocated for the hamming distance and I am still unable to find the source of my memory leak. Allocation as such is not a problem, resident memory is the important thing. Try heap profiling to see what holds on to memory (+RTS -hc would be a good first run). Regards, Arnoldo On Mon, Apr 19, 2010 at 3:47 PM, Daniel Fischer daniel.is.fisc...@web.dewrote: Am Montag 19 April 2010 14:37:33 schrieb John Lato: Is it really necessary to use Strings? I think a packed type, e.g. Vector or ByteString, would be much more efficient here. Not very much if the strings are fairly short (and the list isn't too long, so there's not a big difference in cache-friendliness). If eight-bit characters aren't enough, packing the strings into UArray Int Char gives performance quite close to ByteStrings. Of course this is only likely to be a benefit if you can move away from String entirely. I suspect that hamming2 would perform better then. John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] hamming distance allocation
Am Montag 19 April 2010 17:53:27 schrieb Arnoldo Muller: Hello Daniel: My % GC time is : 75.0% (81.4% elapsed) and I am compiling with -O2. Very bad. Can I see the code? Thank you for clarifying about the pointers. Not to forget the Ints for counting. Slowly my memory grows up and eventually it explodes. I would expect that the list comprehension is lazily evaluated and therefore at any given time I am only executing one hamming distance. The result of the hamming distance is stored into a small statistics datatype I built (only stores sums and sum of squares and the counts). This datatype is updated using a foldr. That might very well be the problem, if you update it with a foldr, you must construct the entire list of 2000^2 hamming-thunks before the work can begin. It's probably better to use foldl' (and make the type strict) so you can start the work immediately. I have no idea where the leak is. What do you see in a .prof file to find a leak (hamming distance has the largest amount of time and %alloc) For finding leaks, heap profiling (-h*) gives more info than -p. The .prof says more about where you spend your time than what hangs on to memory. ? From my .prof file where would you start looking at? - use hamming instead of hamming2 - convertIntToDouble looks suspicious - calculating a few million Hamming distances takes some time, but what about getMyStats, should that really take 25%? filter (\x - x /= 0) $ map (uncurry hammingX) [(xs, ys) | xs - exampl, ys - exampl] filter (/= 0) [hamming xs ys | xs - example, ys - example] And of course, you can trivially avoid half of the work. Best Regards, Arnoldo Muller On Mon, Apr 19, 2010 at 3:18 AM, Daniel Fischer daniel.is.fisc...@web.dewrote: Am Montag 19 April 2010 01:03:14 schrieb Arnoldo Muller: Hello all: I want to generate some hamming distance statistics about a set of strings. As explained in another e-mail in this list, I used the following code to call the functions: (exampl holds the list of strings of size w) filter (\x - x /= 0) $ map (uncurry hammingX) [(xs, ys) | xs - exampl, ys - exampl] I have two hamming functions: -- hamming distance for variable length strings hamming :: String - String - Int hamming x y = hamming' x y 0 where hamming' [] _ !c = c hamming' _ [] !c = c hamming' (x:xs) (y:ys) !c | x == y = hamming' xs ys c | otherwise = hamming' xs ys (c + 1) -- function posted in this mailing list hamming2 :: String - String - Int hamming2 xs ys = length (filter not (zipWith (==) xs ys)) I am executing these functions millions of times and the bottleneck of my program is in them as explained by running in profiling mode with +RTS -K400M -p -RTS The costlier function is the hamming distance COST CENTREMODULE %time %alloc hammingDistances 66.6 41.9 It says that it is performing 41% of the allocations. In the case of hamming2 the allocations go as far as 52%. Allocations are cheap, so that's not necessarily a problem. More important is, what's the maximum residency and how much is copied during GC? Are you compiling with -O2 ? I could understand that there are allocations in hamming2 because we are creating pairs, but in the case of hamming there should be no allocation. Why not? I don't know how GHC counts allocations, but everytime you go from (x:xs) to xs, you need a new pointer to the tail. If that counts as allocation, hamming must allocate a lot, too. How can I execute my hamming functions without allocating memory? Best regards, Arnoldo Muller ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] newbie question how to pass data
First of all, your function func (x,y) s dg =((x*(cos dg) - y*(sin dg)),(x*(sin dg) - y*(cos dg))) does NOT work for type (Float - Float), unless you mean that that is the type of the unused parameter s. Also, your desired type ((Float - Float) - Bool) itself looks suspicious. It must accept any function (without something to apply it to) and arbitrarily return True or False. How will you decide which? I suspect you need another parameter for this function. Second, on the off chance you are trying to calculate the position on a circle scaled then rotated an angle dg from (x,y), that new position is f (x,y) s dg = (s*(x*(cos dg) - y*(sin dg)),s*(x*(sin dg) + y*(cos dg))) in which case you are missing the s and the last minus sign in your formula should be a plus sign. If so, this can be evaluated with greater clarity (and probably accuracy) in polar coordinates: g (x,y) s dg = (r * cos a, r * sin a) where r = s * sqrt (x^2 + y^2) a = atan2 y x + dg Third, if you did not need the scale, I would use an underscore to make that clear: h (x,y) _ dg = (r * cos a, r * sin a) where r = sqrt (x^2 + y^2) a = atan2 y x + dg That's all the observations I can make unless you describe the problem more clearly. Sorry. Dan Mujtaba Boori wrote: sorry ok I am trying to make these calculation func (x,y) s dg =((x*(cos dg) - y*(sin dg)),(x*(sin dg) - y*(cos dg))) This work for type (Float - Float) but how can make it work with ((Float - Float) - Bool) because my main function that I want use with. it takes (Float,Float) -Bool) I need to return the same type ((Float,Float) -Bool) so it could be used with other function. On Mon, Apr 19, 2010 at 5:54 PM, Ozgur Akgun ozgurak...@gmail.com mailto:ozgurak...@gmail.com wrote: Can you at least give an example of how you intend to use this func? Since you do not describe it's behaviour, it is very hard to make a useful comment (at least for me) Best, On 19 April 2010 16:54, Mujtaba Boori mujtaba.bo...@gmail.com mailto:mujtaba.bo...@gmail.com wrote: Hello I am sorry for the silly question. I have a function as the following func:: ((Float,Float) -Bool) - Float - ((Float,Float) - Bool) I am trying to make calculation in this type ((Float,Float) -Bool) with Float and then pass the information to ((Float,Float) - Bool) Thank again appreciated. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org mailto:Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Ozgur Akgun -- Mujtaba Ali Alboori ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: instance Eq (a - b)
Because it is the most utilitarian way to get a bunch of strict ByteStrings out of a lazy one. Yes it exposes an implementation detail, but the alternatives involve an unnatural amount of copying. -Edward Kmett On Sat, Apr 17, 2010 at 6:37 PM, Ashley Yakeley ash...@semantic.org wrote: Ketil Malde wrote: Do we also want to modify equality for lazy bytestrings, where equality is currently independent of chunk segmentation? (I.e. toChunks s1 == toChunks s2 == s1 == s2 but not vice versa.) Why is toChunks exposed? -- Ashley Yakeley ___ 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] hamming distance allocation
Daniel thank you for all your advice. An additional ! bang pattern in convertIntToDouble fixed the issue! Also using a foldl' did the trick. Now the program runs as it should with a constant amount of memory and in a very small amount of time. I believe these problems are one of the major sources of frustration for Haskell newbies. Things that could work in X language easily suddenly become problems in Haskell. When you overcome these issues then you feel happy again that you chose Haskell as the main programming language of your research project. Is there any guide that explains more about the bad consumption pattern. Are there any general rules defined to avoid these issues? It helped me to re-read the chapter on profiling in the Real World Haskell book to sorta understand the problem. Is there a more detailed definition of the problem than in RWH? Regards, Arnoldo On Tue, Apr 20, 2010 at 2:49 AM, Daniel Fischer daniel.is.fisc...@web.dewrote: Am Montag 19 April 2010 17:53:27 schrieb Arnoldo Muller: Hello Daniel: My % GC time is : 75.0% (81.4% elapsed) and I am compiling with -O2. Very bad. Can I see the code? Thank you for clarifying about the pointers. Not to forget the Ints for counting. Slowly my memory grows up and eventually it explodes. I would expect that the list comprehension is lazily evaluated and therefore at any given time I am only executing one hamming distance. The result of the hamming distance is stored into a small statistics datatype I built (only stores sums and sum of squares and the counts). This datatype is updated using a foldr. That might very well be the problem, if you update it with a foldr, you must construct the entire list of 2000^2 hamming-thunks before the work can begin. It's probably better to use foldl' (and make the type strict) so you can start the work immediately. I have no idea where the leak is. What do you see in a .prof file to find a leak (hamming distance has the largest amount of time and %alloc) For finding leaks, heap profiling (-h*) gives more info than -p. The .prof says more about where you spend your time than what hangs on to memory. ? From my .prof file where would you start looking at? - use hamming instead of hamming2 - convertIntToDouble looks suspicious - calculating a few million Hamming distances takes some time, but what about getMyStats, should that really take 25%? filter (\x - x /= 0) $ map (uncurry hammingX) [(xs, ys) | xs - exampl, ys - exampl] filter (/= 0) [hamming xs ys | xs - example, ys - example] And of course, you can trivially avoid half of the work. Best Regards, Arnoldo Muller On Mon, Apr 19, 2010 at 3:18 AM, Daniel Fischer daniel.is.fisc...@web.dewrote: Am Montag 19 April 2010 01:03:14 schrieb Arnoldo Muller: Hello all: I want to generate some hamming distance statistics about a set of strings. As explained in another e-mail in this list, I used the following code to call the functions: (exampl holds the list of strings of size w) filter (\x - x /= 0) $ map (uncurry hammingX) [(xs, ys) | xs - exampl, ys - exampl] I have two hamming functions: -- hamming distance for variable length strings hamming :: String - String - Int hamming x y = hamming' x y 0 where hamming' [] _ !c = c hamming' _ [] !c = c hamming' (x:xs) (y:ys) !c | x == y = hamming' xs ys c | otherwise = hamming' xs ys (c + 1) -- function posted in this mailing list hamming2 :: String - String - Int hamming2 xs ys = length (filter not (zipWith (==) xs ys)) I am executing these functions millions of times and the bottleneck of my program is in them as explained by running in profiling mode with +RTS -K400M -p -RTS The costlier function is the hamming distance COST CENTREMODULE %time %alloc hammingDistances 66.6 41.9 It says that it is performing 41% of the allocations. In the case of hamming2 the allocations go as far as 52%. Allocations are cheap, so that's not necessarily a problem. More important is, what's the maximum residency and how much is copied during GC? Are you compiling with -O2 ? I could understand that there are allocations in hamming2 because we are creating pairs, but in the case of hamming there should be no allocation. Why not? I don't know how GHC counts allocations, but everytime you go from (x:xs) to xs, you need a new pointer to the tail. If that counts as allocation, hamming must allocate a lot, too. How can I execute my hamming functions without allocating memory? Best regards, Arnoldo Muller ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org
Re: [Haskell-cafe] US Patent for the idea of using Haskell to implement UAX #9
On 16/04/10 19:59, Daniel Fischer wrote: Am Freitag 16 April 2010 20:50:25 schrieb Brian Hulley: revealed a link to a US Patent (7120900) for the idea of implementing the Unicode Bidirectional Algorithm (UAX #9 http://www.unicode.org/reports/tr9) in Haskell, making use, as far as I can tell, of nothing more than the normal approach any functional programmer would use, namely separation of concerns etc. In which case the patent should be null and void since obvious ideas aren't patentable, AFAIK. But of course, IANAL, you never know what jurists think a law means, ... First, everyone in this thread needs to stop writing and read http://news.swpat.org/2010/03/transcript-tridgell-patents/ , which is a talk by Andrew Tridgell of Samba fame about patents and how to avoid/invalidate them. His main point is that avoidance is much much easier than invalidation. Now, about obviousness and prior art. The patent system has been shaped by lawsuits. Judges want nice clear dividing lines because otherwise the law becomes unclear and a trial becomes even more of a crapshoot than it already is. This search for bright dividing lines has forced judges to make some decisions that sound rather odd. The problem with the obvious bit is that almost everything is obvious after you've had it explained to you. Sherlock Holmes had this problem with Watson; every time Holmes explained his reasoning Watson realised that the puzzle was absurdly easy and couldn't understand why he hadn't understood it before. Its the same with inventions. So its no use having an engineer on the witness stand testify against a patent by saying I'm skilled in the art and this looks obvious to me. You need something a bit less subjective. So to prove a patent obvious you have to locate some piece of prior art that almost does what is in the patent, then find another piece of prior art that fills the gap, and then find a motivation (such as a problem with the first piece of art) that would lead an engineer to logically put the two together. You can string several such steps together, and the bits of prior art can be as obscure as you want, as long as they actually were published. What you cannot do is assume even the tiniest inventive step in this process. In short the person skilled in the art of patent law isn't any real kind of person, its more like Google with an inference engine attached. (Actually thats a pretty cool idea). Paul. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Re: instance Eq (a - b)
Why is a function that gets a bunch of strict ByteStrings out of a lazy one exposed? In any case, it sounds like a similar situation to (==) on Float and Double. There's a mismatch between the Haskellish desire for a law on (==), and the convenient desire for -0.0 == 0.0, or for exposing toChunks. Which one you prefer depends on your attitude. My point is not so much to advocate for the Haskellish viewpoint than to recognise the tension in the design. Float and Double are pretty ugly anyway from a Haskell point of view, since they break a bunch of other desirable properties for (+), (-) and so on. The theoretical reason for using floating point rather than fixed point is when one needs relative precision over a range of scales: for other needs one should use fixed point or rationals. I added a Fixed type to base, but it doesn't implement the functions in the Floating class and I doubt it's as fast as Double for common arithmetic functions. It would be possible to represent the IEEE types in a Haskellish way, properly revealing all their ugliness. This would be gratifying for us purists, but would annoy those just trying to get some numeric calculations done. -- Ashley Yakeley On Mon, 2010-04-19 at 15:32 -0400, Edward Kmett wrote: Because it is the most utilitarian way to get a bunch of strict ByteStrings out of a lazy one. Yes it exposes an implementation detail, but the alternatives involve an unnatural amount of copying. -Edward Kmett On Sat, Apr 17, 2010 at 6:37 PM, Ashley Yakeley ash...@semantic.org wrote: Ketil Malde wrote: Do we also want to modify equality for lazy bytestrings, where equality is currently independent of chunk segmentation? (I.e. toChunks s1 == toChunks s2 == s1 == s2 but not vice versa.) Why is toChunks exposed? -- Ashley Yakeley ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Bulk Synchronous Parallel
Hey everyone, Has anyone done any work with bulk synchronous parallel computing in Haskell? The idea behind the model is that you divide your computation into a series of computation and communication phases, and it has recently occurred to me that this might be an ideal setup for parallelizing a pure language like Haskell because you can think of it as alternating between a stage that independently applies a bunch of functions to a bunch of independent chunks of data and a stage that applies a big function to all of the chunks that recombines them into new chunks for the next parallel phase, so that all stages are conceptually pure even if eventually the second stage is turned into something involving communication and hence side-effectful under the hood. Experiences? Thoughts? Cheers, Greg ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] US Patent for the idea of using Haskell to implement UAX #9
This patent has zero practical impact. When the patent was written there was no Unicode support, so the implementation translates the input into lists of integers instead of lists of characters. Crucially this step was also written into all three independent claims (which are the only bit of a patent that actually matters). So you are free to re-implement this algorithm provided that you manipulate lists of characters rather than lists of integers. Now that GHC has full unicode support this should not be a problem. Paul. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Strange error with type classes + associated types
On Mon, Apr 19, 2010 at 09:40:25AM -0700, Conal Elliott wrote: On Sun, Apr 18, 2010 at 9:02 PM, Brent Yorgey byor...@seas.upenn.eduwrote: Conal, Thanks for looking into this! Making (:-*) into a proper type seems promising. I did try wrapping (:-*) in a newtype but that didn't help (although I didn't expect it to). What do you mean by a proper type? I didn't know what Roman meant either, though I guessed he meant a newtype or data type. Yes, that's what I meant too, sorry for the imprecise terminology. I see you just uploaded a new version of vector-space; what's new in 0.6.2? The dependency on the Boolean package now specifies = 0.0.1. Ah, OK. -Brent ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: scan-0.1.0.3, a Haskell style scanner
=On Mon, Apr 19, 2010 at 06:24:25PM +0200, Henning Thielemann wrote: Christian Maeder schrieb: Henning Thielemann schrieb: The updated Haskell code might be written to a new file by default. Then I can interactively transfer the corrections I like to the original code using Kompare. I would also not use '-' as option. How would you extend the set of options later, say for de-/selection of specific warnings? I don't know (and have) Kompare, thanks for mentioning it. It's part of KDE. There is also TkDiff, but I don't know whether it supports moving around changes. Gnome users may like using Meld as much as I do. http://meld.sourceforge.net/ -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Bulk Synchronous Parallel
On Mon, Apr 19, 2010 at 11:03 PM, Gregory Crosswhite gcr...@phys.washington.edu wrote: Hey everyone, Has anyone done any work with bulk synchronous parallel computing in Haskell? The idea behind the model is that you divide your computation into a series of computation and communication phases, and it has recently occurred to me that this might be an ideal setup for parallelizing a pure language like Haskell because you can think of it as alternating between a stage that independently applies a bunch of functions to a bunch of independent chunks of data and a stage that applies a big function to all of the chunks that recombines them into new chunks for the next parallel phase, so that all stages are conceptually pure even if eventually the second stage is turned into something involving communication and hence side-effectful under the hood. Experiences? Thoughts? You may want to check out NDP, e.g. here: http://www.haskell.org/haskellwiki/GHC/Data_Parallel_Haskell http://www.haskell.org/haskellwiki/GHC/Data_Parallel_HaskellIt's at a higher level of abstraction, in a way. You don't need to worry about the dicing up and recombining, the compiler takes care of it for you. You just write things in terms of parallel arrays (which can be small, e.g. 2 element wide) and the compiler will fuse/flatten these together into big bulk parallel computations with communication between them. -- Sebastian Sylvan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Bulk Synchronous Parallel
Thanks for the link; my ultimate interest, though, is in an architecture that could scale to multiple machines rather than multiple cores with shared memory on a single machine. Has there been any interest and/or progress in making DPH run on multiple machines and other NUMA architectures? Cheers, Greg On Apr 19, 2010, at 3:33 PM, Sebastian Sylvan wrote: On Mon, Apr 19, 2010 at 11:03 PM, Gregory Crosswhite gcr...@phys.washington.edu wrote: Hey everyone, Has anyone done any work with bulk synchronous parallel computing in Haskell? The idea behind the model is that you divide your computation into a series of computation and communication phases, and it has recently occurred to me that this might be an ideal setup for parallelizing a pure language like Haskell because you can think of it as alternating between a stage that independently applies a bunch of functions to a bunch of independent chunks of data and a stage that applies a big function to all of the chunks that recombines them into new chunks for the next parallel phase, so that all stages are conceptually pure even if eventually the second stage is turned into something involving communication and hence side-effectful under the hood. Experiences? Thoughts? You may want to check out NDP, e.g. here: http://www.haskell.org/haskellwiki/GHC/Data_Parallel_Haskell It's at a higher level of abstraction, in a way. You don't need to worry about the dicing up and recombining, the compiler takes care of it for you. You just write things in terms of parallel arrays (which can be small, e.g. 2 element wide) and the compiler will fuse/flatten these together into big bulk parallel computations with communication between them. -- Sebastian Sylvan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Asynchronous exception wormholes kill modularity
On Mon, Apr 19, 2010 at 5:54 PM, Simon Marlow marlo...@gmail.com wrote: So I think I like this variant, even though it adds a little API overhead. Anyone else have any thoughts on this? I do think the RankNTypes version: mask :: ((forall b. IO b - IO b) - IO a) - IO a is easier to use and explain because it doesn't require the extra 'restore' function. What are the problems with RankNTypes? I can imagine that one problem is not being haskell98. However the Control.Exception module is also not haskell98 due to the existentially quantified SomeException constructor: data SomeException = forall e . Exception e = SomeException e regards, Bas ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANNOUNCE: Agata-0.2.0
2010/4/19 Jonas Almström Duregård jonas.dureg...@gmail.com: If this is to be used with QuickCheck maybe it should be named that way. Certainly worth considering. There seems to be no convenient way of renaming packages on Hackage though, is there? AFAIK hackage has support for deprecating packages in favor of others. This functionality is not exposed to regular users but you could mail one of the maintainers (Ross Paterson) to rename your package. Bas ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Continual delivery status notification failures
Can the owner of c10b66c97b5cd09384aa9f82ecd95...@orangeat.blackberry.com please fix their emails up (or the haskell-cafe admins remove that address), as I keep getting delivery status notification failure messages over a week after I send an email to the list (I would have emailed that address directly, except if they can't get -cafe they probably can't get any emails...). -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] newbie question how to pass data
Thanks Dan. Great help but my problem has not solved yet This doesn't work for type ((Float - Float)-Bool) to make it easier ignore the rotation and suppose I want just multiplay with whatever (x ,y) and return the result to this type ((Float - Float)-Bool) note this type is shorten and replace by t Type Point = (Float, Float) Type Bitmap = Point - Bool so the function type actually func :: Bitmap - Float - Bitmap I want to take Bitmap do some calculation on Bitmap the return it as Bitmap. GHCi response for Dan method is this Couldn't match expected type `Bitmap' against inferred type `(a, b)' so it is missing a Bool. hopefully it is clear . On Mon, Apr 19, 2010 at 7:02 PM, Dan Weston weston...@imageworks.comwrote: First of all, your function func (x,y) s dg =((x*(cos dg) - y*(sin dg)),(x*(sin dg) - y*(cos dg))) does NOT work for type (Float - Float), unless you mean that that is the type of the unused parameter s. Also, your desired type ((Float - Float) - Bool) itself looks suspicious. It must accept any function (without something to apply it to) and arbitrarily return True or False. How will you decide which? I suspect you need another parameter for this function. Second, on the off chance you are trying to calculate the position on a circle scaled then rotated an angle dg from (x,y), that new position is f (x,y) s dg = (s*(x*(cos dg) - y*(sin dg)),s*(x*(sin dg) + y*(cos dg))) in which case you are missing the s and the last minus sign in your formula should be a plus sign. If so, this can be evaluated with greater clarity (and probably accuracy) in polar coordinates: g (x,y) s dg = (r * cos a, r * sin a) where r = s * sqrt (x^2 + y^2) a = atan2 y x + dg Third, if you did not need the scale, I would use an underscore to make that clear: h (x,y) _ dg = (r * cos a, r * sin a) where r = sqrt (x^2 + y^2) a = atan2 y x + dg That's all the observations I can make unless you describe the problem more clearly. Sorry. Dan Mujtaba Boori wrote: sorry ok I am trying to make these calculation func (x,y) s dg =((x*(cos dg) - y*(sin dg)),(x*(sin dg) - y*(cos dg))) This work for type (Float - Float) but how can make it work with ((Float - Float) - Bool) because my main function that I want use with. it takes (Float,Float) -Bool) I need to return the same type ((Float,Float) -Bool) so it could be used with other function. On Mon, Apr 19, 2010 at 5:54 PM, Ozgur Akgun ozgurak...@gmail.commailto: ozgurak...@gmail.com wrote: Can you at least give an example of how you intend to use this func? Since you do not describe it's behaviour, it is very hard to make a useful comment (at least for me) Best, On 19 April 2010 16:54, Mujtaba Boori mujtaba.bo...@gmail.com mailto:mujtaba.bo...@gmail.com wrote: Hello I am sorry for the silly question. I have a function as the following func:: ((Float,Float) -Bool) - Float - ((Float,Float) - Bool) I am trying to make calculation in this type ((Float,Float) -Bool) with Float and then pass the information to ((Float,Float) - Bool) Thank again appreciated. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org mailto:Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Ozgur Akgun -- Mujtaba Ali Alboori -- Mujtaba Ali Alboori ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Move MonadIO to base
Anders Kaseorg wrote: Isaac Dupree wrote: Do you see the difference? The effects are sequenced in different places. The return/join pair moves all the effects *outside* the operations such as catch... thus defeating the entire purpose of morphIO. Yes; my question is more whether Wren has a more clever way to get an isomorphism (forall b. (m a - IO b) - IO b) - IO (m a) that would make the simpler interface work out. (Or maybe I misunderstood what he was getting at.) Yeah no, that's what I was getting at. Since it doesn't quite work out, I should probably rethink my appeal to parametricity re Kleisli arrows.[1] That is, when we take the monad to be the identity monad or equivalently to be no monad, then parametricity yields: (forall b. (m a - b) - b) - (m a). Apparently this makes some sort of appeal to special properties about the identity monad (e.g., being both pointed and copointed) since it doesn't generalize to every monad in the way I suggested. musing Perhaps the correct version is this? forall a n. Monad n = (forall b. (m a - n b) - n b) - n (m (n a)) Of course that may not solve your H98 concerns. Not all monads m provide a universal law (forall n, n.m.n - n.m) so to define the law you'd need MPTCs to relate m and n. But if we monomorphize to just n=IO that would simplify things; but then we'd need (Traversable m) in order to collapse the two layers of IO... /musing [1] Oleg discusses a similar need to be careful about appeals to parametricity when dealing with monads: http://okmij.org/ftp/Computation/lem.html -- Live well, ~wren ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Move MonadIO to base
wren ng thornton wrote: Anders Kaseorg wrote: Isaac Dupree wrote: Do you see the difference? The effects are sequenced in different places. The return/join pair moves all the effects *outside* the operations such as catch... thus defeating the entire purpose of morphIO. Yes; my question is more whether Wren has a more clever way to get an isomorphism (forall b. (m a - IO b) - IO b) - IO (m a) that would make the simpler interface work out. (Or maybe I misunderstood what he was getting at.) Yeah no, that's what I was getting at. Since it doesn't quite work out, I should probably rethink my appeal to parametricity re Kleisli arrows.[1] No, my parametricity was correct, just the implementations were wrong: {-# LANGUAGE RankNTypes #-} module MorphIO where import Prelude hiding (catch) import Control.Monad import qualified Control.Exception as E import Control.Exception (NonTermination(..)) class Monad m = MonadMorphIO m where morphIO :: (forall b. (m a - IO b) - IO b) - m a class Monad m = MonadJoinIO m where -- | Embed the IO into the monad m joinIO :: IO (m a) - m a -- | Extract the IO computation to the top level, -- rendering the m pure from IO. partIO :: m a - IO (m a) joinIO' m = morphIO (m =) morphIO' f = joinIO (f partIO) instance MonadMorphIO IO where morphIO f = f id instance MonadJoinIO IO where joinIO = join partIO = fmap return -- N.B. fmap return /= return catch m h = morphIO $ \w - w m `E.catch` \e - w (h e) catch' m h = morphIO' $ \w - w m `E.catch` \e - w (h e) test = E.throwIO NonTermination `catch` \NonTermination - return moo test' = E.throwIO NonTermination `catch'` \NonTermination - return moo -- Live well, ~wren ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe