Re: [GHC] #5786: Dynanmic way fails when GHC built with LLVM backend
#5786: Dynanmic way fails when GHC built with LLVM backend -+-- Reporter: dterei| Owner: dterei Type: bug | Status: new Priority: normal| Milestone: 7.6.1 Component: Compiler (LLVM) | Version: 7.4.1-rc1 Keywords:| Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Runtime crash Difficulty: Unknown |Testcase: Blockedby:|Blocking: Related: #5757 | -+-- Comment(by dterei): Still a problem, error reported is: {{{ Wrong exit code (expected 0 , actual 134 ) Stdout:11 Stderr: largeArray: internal error: evacuate: strange closure type -385875968 (GHC version 7.5.20120328 for x86_64_unknown_linux) Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug Aborted }}} -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/5786#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler ___ Glasgow-haskell-bugs mailing list Glasgow-haskell-bugs@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
Re: [GHC] #5976: Panic in a user Template Haskell function is wrongly reported as a GHC bug (was: GHC compiler panic when using {-# UNPACK #-} and template Haskell)
#5976: Panic in a user Template Haskell function is wrongly reported as a GHC bug -+-- Reporter: SimonMeier | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler|Version: 7.4.1 Resolution: | Keywords: Os: Linux | Architecture: Unknown/Multiple Failure: Compile-time crash | Difficulty: Unknown Testcase: | Blockedby: Blocking: |Related: -+-- Comment(by simonpj): Ah, I see. Yes, that is a good point, thank you. I've changed the title. Ian or Paolo, might you look at this (in `TcSplice` I think)? Simon -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/5976#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler ___ Glasgow-haskell-bugs mailing list Glasgow-haskell-bugs@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
Re: [GHC] #5978: Type error in one function causes wrong type error report in another function in the presence of functionally dependent types
#5978: Type error in one function causes wrong type error report in another function in the presence of functionally dependent types +--- Reporter: Lemming | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type checker) | Version: 7.4.1 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: GHC rejects valid program Difficulty: Unknown |Testcase: Blockedby: |Blocking: Related: | +--- Comment(by Lemming): Sorry ... monoFoo is correct and monoBar is incorrect. But when I compile that module GHC reports two type errors: One for monoFoo and one for monoBar. If I remove monoBar, then monoFoo is accepted by GHC. The result of monoBar is Double, thus fromB=Double. The argument of polyBar in monoBar is of type Float, thus fromA=Float. From the functional dependencies it follows toB=Bool and toA=Char. Thus id would need type Char - Bool, which is a type error and this one is correctly spotted by GHC. But additionally also a type error for monoBar is reported, although monoBar is correct. It has type Float and it follows to=Char, but the 'to' type is not used in monoBar. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/5978#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler ___ Glasgow-haskell-bugs mailing list Glasgow-haskell-bugs@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
Re: [GHC] #5899: RTS crash w/ strange closure type 603975781 on OS X 10.8
#5899: RTS crash w/ strange closure type 603975781 on OS X 10.8 ---+ Reporter: dylukes | Owner: Type: bug | Status: new Priority: high| Milestone: 7.4.2 Component: Runtime System | Version: 7.4.1 Keywords: rts, strange closure, internal error, os x | Os: MacOS X Architecture: x86_64 (amd64) | Failure: Runtime crash Difficulty: Unknown |Testcase: Blockedby: |Blocking: Related: | ---+ Comment(by simonmar): Regarding the documentation, the documentation for `-no_order_inits` says When the -order_file option is not used, the linker lays out functions in object file order and it moves all initializer routines to the start of the __text section and terminator routines to the end. Use this option to disable the automatic rearrangement of initializers and terminators. So this explicitly says that functions are laid out in object file order when `-order_file` is ''not'' used. Either the documentation is wrong, or the implementation has a bug. In principle we could use `-order_file`, but as Irene says it is difficult to arrange. We don't know the list of symbols before linking because they come from libraries, so we would have to link the program twice: once to find the list of object files, then construct the symbol list by looking up the object files in the libraries, and then link again with `-order_file` and the constructed list of symbols. This could all be quite slow. Irene: I don't think reordering is gaining us anything. The linker doesn't have any locality information that it could use to do a sensible reordering. I suspect that all it is doing is filling in gaps caused by alignment with small symbols to reduce the size of the linked binary a tiny bit. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/5899#comment:27 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler ___ Glasgow-haskell-bugs mailing list Glasgow-haskell-bugs@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
Re: [GHC] #5976: Panic in a user Template Haskell function is wrongly reported as a GHC bug
#5976: Panic in a user Template Haskell function is wrongly reported as a GHC bug -+-- Reporter: SimonMeier | Owner: pcapriotti Type: bug | Status: new Priority: normal | Milestone: Component: Compiler|Version: 7.4.1 Resolution: | Keywords: Os: Linux | Architecture: Unknown/Multiple Failure: Compile-time crash | Difficulty: Unknown Testcase: | Blockedby: Blocking: |Related: -+-- Changes (by pcapriotti): * owner: = pcapriotti -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/5976#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler ___ Glasgow-haskell-bugs mailing list Glasgow-haskell-bugs@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
Re: [GHC] #5978: Type error in one function causes wrong type error report in another function in the presence of functionally dependent types
#5978: Type error in one function causes wrong type error report in another function in the presence of functionally dependent types +--- Reporter: Lemming | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type checker) | Version: 7.4.1 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: GHC rejects valid program Difficulty: Unknown |Testcase: Blockedby: |Blocking: Related: | +--- Changes (by simonpj): * cc: dimitris@… (added) Comment: OK I see what is happening. From the two definitions we get these wanted constraints: {{{ monoFoo: mf1: C Float alpha monoBar: mb1: C Float beta, mb2: C Double beta }}} where `alpha` and `beta` are otherwise-unconstrained unification variables. Now if we first do fundeps wrt the `instance` decls, we get `alpha = Char` from `mf1`, `beta = Char` from `mb1` and `beta = Bool` from `mb2`, the latter two yield an error. But if we first do fundeps ''between'' the wanted constraints, we get `alpha = beta`, so that leaves us with `(mf1: C Float alpha, mb2: C Double alpha)`. Now we can solve `mb2` via the fundep with the `instance` to give `alpha=Bool`, and that leaves an error for the innocent `mf1`! Even this isn't quite what happens. Functional dependencies are a pain. Simon -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/5978#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler ___ Glasgow-haskell-bugs mailing list Glasgow-haskell-bugs@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
Re: [GHC] #5978: Type error in one function causes wrong type error report in another function in the presence of functionally dependent types
#5978: Type error in one function causes wrong type error report in another function in the presence of functionally dependent types +--- Reporter: Lemming | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type checker) | Version: 7.4.1 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: GHC rejects valid program Difficulty: Unknown |Testcase: Blockedby: |Blocking: Related: | +--- Comment(by Lemming): Would you suggest that I convert my code to type families? -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/5978#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler ___ Glasgow-haskell-bugs mailing list Glasgow-haskell-bugs@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
Re: [GHC] #5978: Type error in one function causes wrong type error report in another function in the presence of functionally dependent types
#5978: Type error in one function causes wrong type error report in another function in the presence of functionally dependent types +--- Reporter: Lemming | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type checker) | Version: 7.4.1 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: GHC rejects valid program Difficulty: Unknown |Testcase: Blockedby: |Blocking: Related: | +--- Comment(by simonpj): I would certainly give type families a try, yes. I'd be interested to hear how it goes. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/5978#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler ___ Glasgow-haskell-bugs mailing list Glasgow-haskell-bugs@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
Re: [GHC] #5839: ARM linker support
#5839: ARM linker support +--- Reporter: bgamari | Owner: pcapriotti Type: feature request | Status: patch Priority: high | Milestone: 7.4.2 Component: Runtime System | Version: Keywords: | Os: Unknown/Multiple Architecture: arm | Failure: None/Unknown Difficulty: Unknown |Testcase: Blockedby: |Blocking: Related: | +--- Changes (by simonmar): * owner: simonmar = pcapriotti Comment: Paulo, can you handle this one please? -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/5839#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler ___ Glasgow-haskell-bugs mailing list Glasgow-haskell-bugs@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
Re: [GHC] #5975: ghci can't load file whose name contains non-ASCII chars?
#5975: ghci can't load file whose name contains non-ASCII chars? ---+ Reporter: j.waldmann | Owner: Type: bug | Status: patch Priority: normal | Milestone: Component: GHCi| Version: 7.4.1 Keywords: | Os: Linux Architecture: x86_64 (amd64) | Failure: None/Unknown Difficulty: Unknown |Testcase: Blockedby: |Blocking: Related: | ---+ Comment(by pcapriotti): The patch for this issue does fix the problem, but uncovers a nasty race condition in the GHCi debugger. Here's the scenario: 1. -fbreak-on-exception is on 2. `runStmt` spawns a thread to evaluate a computation 3. the computation throws, and consequently stays blocked on its `breakMVar` 4. a module is loaded, which kills the thread from step 2, waking it up 5. a new computation is started, which can set exceptionFlag back to 1 before the previous thread terminates, interfering with the global state in an unpredictable way This is happening even before my patch for the encoding bug, but it was a lot harder to reproduce. The patch made the module loading code faster, so now it can be reproduced rather easily on the testcase break011. The solution seems to be to just wait in step 4 until the killed thread terminates, by taking its statusMVar. Patch attached. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/5975#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler ___ Glasgow-haskell-bugs mailing list Glasgow-haskell-bugs@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
Re: [saj...@gmail.com: Google Summer of Code: a NUMA wishlist!]
On 28/03/2012 16:57, Tyson Whitehead wrote: On March 28, 2012 04:41:16 Simon Marlow wrote: Sure. Do you have a NUMA machine to test on? My understanding is non-NUMA machines went away when the AMD and Intel moved away from frontside buses (FSB) and integrated the memory controllers on die. Intel is more recent to this game. I believe AMD's last non-NUMA machines where the Athalon XP series and Intel's the Core 2 series. An easy way to see what you've got is to see what 'numactl --hardware' says. If the node distance matrix is not uniform, you have NUMA hardware. As an example, on a 8 socket Opteron machine (32 cores) you get $ numactl --hardware available: 8 nodes (0-7) node 0 size: 16140 MB node 0 free: 3670 MB node 1 size: 16160 MB node 1 free: 3472 MB node 2 size: 16160 MB node 2 free: 4749 MB node 3 size: 16160 MB node 3 free: 4542 MB node 4 size: 16160 MB node 4 free: 3110 MB node 5 size: 16160 MB node 5 free: 1963 MB node 6 size: 16160 MB node 6 free: 1715 MB node 7 size: 16160 MB node 7 free: 2862 MB node distances: node 0 1 2 3 4 5 6 7 0: 10 20 20 20 20 20 20 20 1: 20 10 20 20 20 20 20 20 2: 20 20 10 20 20 20 20 20 3: 20 20 20 10 20 20 20 20 4: 20 20 20 20 10 20 20 20 5: 20 20 20 20 20 10 20 20 6: 20 20 20 20 20 20 10 20 7: 20 20 20 20 20 20 20 10 Well, you learn something new every day! On the new 32-core Opteron box we have here: available: 8 nodes (0-7) node 0 cpus: 0 4 8 12 node 0 size: 8182 MB node 0 free: 1994 MB node 1 cpus: 16 20 24 28 node 1 size: 8192 MB node 1 free: 2783 MB node 2 cpus: 3 7 11 15 node 2 size: 8192 MB node 2 free: 2961 MB node 3 cpus: 19 23 27 31 node 3 size: 8192 MB node 3 free: 5359 MB node 4 cpus: 2 6 10 14 node 4 size: 8192 MB node 4 free: 3030 MB node 5 cpus: 18 22 26 30 node 5 size: 8192 MB node 5 free: 4667 MB node 6 cpus: 1 5 9 13 node 6 size: 8192 MB node 6 free: 3240 MB node 7 cpus: 17 21 25 29 node 7 size: 8192 MB node 7 free: 4031 MB node distances: node 0 1 2 3 4 5 6 7 0: 10 16 16 22 16 22 16 22 1: 16 10 16 22 22 16 22 16 2: 16 16 10 16 16 16 16 22 3: 22 22 16 10 16 16 22 16 4: 16 22 16 16 10 16 16 16 5: 22 16 16 16 16 10 22 22 6: 16 22 16 22 16 22 10 16 7: 22 16 22 16 16 22 16 10 The node distances on this box are less uniform than yours. Cheers, Simon ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Code review for new primop's CMM code?
Perhaps a question mark is more appropriate in the title. It is a code review I am seeking, not one on offer ;-). On Thu, Mar 29, 2012 at 12:56 AM, Ryan Newton rrnew...@gmail.com wrote: Hi all, In preparation for students working on concurrent data structures GSOC(s), I wanted to make sure they could count on CAS for array elements as well as IORefs. The following patch represents my first attempt: https://github.com/rrnewton/ghc/commit/18ed460be111b47a759486677960093d71eef386 It passes a simple test [Appendix 2 below], but I am very unsure as to whether the GC write barrier is correct. Could someone do a code-review on the following few lines of CMM: if (GET_INFO(arr) == stg_MUT_ARR_PTRS_CLEAN_info) { SET_HDR(arr, stg_MUT_ARR_PTRS_DIRTY_info, CCCS); len = StgMutArrPtrs_ptrs(arr); // The write barrier. We must write a byte into the mark table: I8[arr + SIZEOF_StgMutArrPtrs + WDS(len) + (ind MUT_ARR_PTRS_CARD_BITS )] = 1; } Thanks, -Ryan -- Appendix 1: First draft code CMM definition for casArray# --- stg_casArrayzh /* MutableArray# s a - Int# - a - a - State# s - (# State# s, Int#, a #) */ { W_ arr, p, ind, old, new, h, len; arr = R1; // anything else? ind = R2; old = R3; new = R4; p = arr + SIZEOF_StgMutArrPtrs + WDS(ind); (h) = foreign C cas(p, old, new) []; if (h != old) { // Failure, return what was there instead of 'old': RET_NP(1,h); } else { // Compare and Swap Succeeded: if (GET_INFO(arr) == stg_MUT_ARR_PTRS_CLEAN_info) { SET_HDR(arr, stg_MUT_ARR_PTRS_DIRTY_info, CCCS); len = StgMutArrPtrs_ptrs(arr); // The write barrier. We must write a byte into the mark table: I8[arr + SIZEOF_StgMutArrPtrs + WDS(len) + (ind MUT_ARR_PTRS_CARD_BITS )] = 1; } RET_NP(0,h); } } -- Appendix 2: Simple test file; when run it should print: --- -- Perform a CAS within a MutableArray# -- 1st try should succeed: (True,33) -- 2nd should fail: (False,44) -- Printing array: -- 33 33 33 44 33 -- Done. --- {-# Language MagicHash, UnboxedTuples #-} import GHC.IO import GHC.IORef import GHC.ST import GHC.STRef import GHC.Prim import GHC.Base import Data.Primitive.Array import Control.Monad -- -- | Write a value to the array at the given index: casArrayST :: MutableArray s a - Int - a - a - ST s (Bool, a) casArrayST (MutableArray arr#) (I# i#) old new = ST$ \s1# - case casArray# arr# i# old new s1# of (# s2#, x#, res #) - (# s2#, (x# ==# 0#, res) #) {-# NOINLINE mynum #-} mynum :: Int mynum = 33 main = do putStrLn Perform a CAS within a MutableArray# arr - newArray 5 mynum res - stToIO$ casArrayST arr 3 mynum 44 res2 - stToIO$ casArrayST arr 3 mynum 44 putStrLn$ 1st try should succeed: ++show res putStrLn$ 2nd should fail: ++show res2 putStrLn Printing array: forM_ [0..4] $ \ i - do x - readArray arr i putStr ( ++show x) putStrLn putStrLn Done. ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: [Haskell] [Haskell-cafe] ANNOUNCE: haskell-src-exts-1.13.0
On 28Mar, 2012, at 10:52 PM, dag.odenh...@gmail.com wrote: On 28 March 2012 21:05, Jurriaan Hage j.h...@uu.nl wrote: Our first year students will be very unhappy to hear this. Wait, what? The improvements in haskell-src-exts will make my Haskell plagiarism detector Holmes more robust and will allow me to detect plagiarism more easily during our bachelor level functional programming course. I admit to being somewhat provocative in my statement: only a small percentage of students plagiarises (as far as we have been able to tell), but some of them really do. Some of our master students will, on the other hand, be very happy with the improved haskell-src-exts, as am I. They are the ones that contribute to constructing tools such as Holmes. Jur ___ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
[Haskell] Faça parte da minha rede no LinkedIn
LinkedIn Eu gostaria de adicioná-lo à minha rede profissional no LinkedIn. -Carlos Camarao Carlos Camarao Figueiredo Professor na UFMG Belo Horizonte e Região, Brasil Confirme que você conhece Carlos Camarao Figueiredo: https://www.linkedin.com/e/-y1615u-h0e41zcs-6/isd/6485083911/4PS7AfCQ/?hs=falsetok=1wHc5Zc1WW0Bc1 -- Você está recebendo convites de conexão por e-mail. Clique aqui para parar de recebê-los: http://www.linkedin.com/e/-y1615u-h0e41zcs-6/A5eR2FIG5M9-4jk43rQ4JqtVY2yX2KP/goo/haskell%40haskell%2Eorg/20061/I2249830551_1/?hs=falsetok=03ug80yOSW0Bc1 (c) 2012 LinkedIn Corporation. 2029 Stierlin Ct, Mountain View, CA 94043 - EUA. ___ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
Re: [Haskell-cafe] adding the elements of two lists
On Sun, Mar 25, 2012 at 5:06 AM, Michael Snoyman mich...@snoyman.com wrote: On Sun, Mar 25, 2012 at 2:01 PM, TP paratribulati...@free.fr wrote: Hello, My primary problem may be reduced to adding elements of two lists: [1,2,3] + [4,5,6] = [5,7,9] My first idea was to declare a list of Int as an instance of Num, and define (+) in the correct way. However, it seems it is not possible to do that: --- instance Num [Int] where l1 + l2 = --- Why? It seems it is necessary to do: -- newtype ListOfInt = ListOfInt { getList :: [Int] } deriving (Show, Eq) instance Num ListOfInt where l1 + l2 = ... --- Am I correct? Is it the best way to do that? Now, what is the most usual way to implement l1+l2? I have just read about applicative functors, with which I can do: --- import Control.Applicative let l1 = [1,2,3] let l2 = [4,5,6] print $ getZipList $ (+) $ ZipList l1 * ZipList l2 [5,7,9] --- Is it the correct way to do that? I have tried: --- instance Num ListOfInt where l1 + l2 = ListOfInt $ getZipList $ (+) $ ZipList (getList l1) * ZipList (getList l2) --- Isn't it too much complicated? Thanks TP ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe A simple solution is to use the zipWith[1] function: zipWith (+) [1,2,3] [4,5,6] == [5,7,9] It takes a bit of time to get acquainted with all of the incredibly convenient functions in base, but once you know them, it can greatly simplify your code. Michael Not knowing zipWith, I usually write map (uncurry (+)) (zip [1,2,3] [4,5,6]) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] a code that cannot compile with or without NoMonomorphismRestriction
Hi I have met a piece of code that cannot be compiled whether I add or remove the NoMonomorphismRestriction flag (as of GHC 7.0.4, Haskell platform 2011.4.0.0).I have extracted a minimal example below: {-# LANGUAGE NoMonomorphismRestriction #-} (f1, f2) = let commond_definitions = undefined in let f1 = id.show f2 x = ( x) in (f1, f2) I needed this format because there are many shared definitions in common_definitions for f1 and f2, and I want to keep them local. If I compile them with NoMonomorphismRestriction, I get: D:\work\test.hs:7:8: Ambiguous type variable `a0' in the constraint: (Show a0) arising from a use of `f1' Possible cause: the monomorphism restriction applied to the following: f1 :: a0 - String (bound at D:\work\hsOcaml\test.hs:2:2) Probable fix: give these definition(s) an explicit type signature In the expression: f1 In the expression: (f1, f2) In the expression: let f1 = id . show f2 x = ( x) in (f1, f2)D:\work\test.hs:7:12: Ambiguous type variable `a1' in the constraint: (Ord a1) arising from a use of `f2' Possible cause: the monomorphism restriction applied to the following: f2 :: a1 - a1 - Bool (bound at D:\work\hsOcaml\test.hs:2:6) Probable fix: give these definition(s) an explicit type signature In the expression: f2 In the expression: (f1, f2) In the expression: let f1 = id . show f2 x = ( x) in (f1, f2) Failed, modules loaded: none. If I comment out -- {-# LANGUAGE NoMonomorphismRestriction #-} I get: D:\work\hsOcaml\test.hs:4:17: Ambiguous type variable `a0' in the constraint: (Show a0) arising from a use of `show' Possible cause: the monomorphism restriction applied to the following: f1 :: a0 - String (bound at D:\work\hsOcaml\test.hs:2:2) Probable fix: give these definition(s) an explicit type signature or use -XNoMonomorphismRestriction In the second argument of `(.)', namely `show' In the expression: id . show In an equation for `f1': f1 = id . showD:\work\hsOcaml\test.hs:7:12: Ambiguous type variable `a1' in the constraint: (Ord a1) arising from a use of `f2' Possible cause: the monomorphism restriction applied to the following: f2 :: a1 - a1 - Bool (bound at D:\work\hsOcaml\test.hs:2:6) Probable fix: give these definition(s) an explicit type signature or use -XNoMonomorphismRestriction In the expression: f2 In the expression: (f1, f2) In the expression: let f1 = id . show f2 x = ( x) in (f1, f2) Failed, modules loaded: none. Can anyone show me why this does not work and how to fix it (e.g. by adding type signature as the error message suggested)?I tried to add type signature by couldn't figure out the right way of doing it. Thanks in advance! Ting ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] adding the elements of two lists
Richard O'Keefe o...@cs.otago.ac.nz writes: newtype PS a = PS [a] deriving (Eq, Show) u f (PS x)= PS $ map f x b f (PS x) (PS y) = PS $ zipWith f x y to_ps x = PS (x : repeat 0) BTW, isn't this a good candidate for an Applicative instance (similar to ZipList)? u f p = f $ p -- or u = fmap b f p1 p2 = f $ p1 * p2 Not a big deal for the Num instance, perhaps, but more general than u and b, and it might make it easier to work with in other ways. -k -- If I haven't seen further, it is by standing in the footprints of giants ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Fail-back monad
Alberto G. Corona wrote about a monad to set a checkpoint and be able to repeatedly go to that checkpoint and re-execute the computations following the checkpoint. http://haskell-web.blogspot.com.es/2012/03/failback-monad.html The typical example is as follows. test= runBackT $ do lift $ print will not return back here liftBackPoint $ print will return here n2 - lift $ getLine lift $ print second input n3 - lift $ getLine if n3 == back then fail else lift $ print $ n2++n3 Let us first consider a slightly simplified problem, with a different signature for liftBackPoint. Rather than writing do liftBackPoint $ print will return here other_computation we will write do backPoint $ do lift $ print will return here other_computation In that case, backPoint will be implemented with the Exception or Error monad. For example, backPoint :: Monad m = ErrorT SomeException m a - ErrorT SomeException m a backPoint m = catchError m handler where handler e | Just RestartMe - fromException e = backPoint m handler e = throwError e -- other errors propagate up We designate one exception RestartMe as initiating the restart from the checkpoint. Other exceptions will propagate as usual. Obviously, if we are in IO or some MonadIO, we could use the regular exception-handling facilities: throw/catch. Suppose however that marking of the checkpoint should be a single action rather that exception-like handling form. Then we need the continuation monad: type BackT r m a = ContT r (ErrorT SomeException m) a backPointC :: Monad m = ContT e (ErrorT SomeException m) () backPointC = ContT (\k - backPoint (k ())) (we have re-used the earlier backPoint). Incidentally, the continuation monad will be faster than BackT in the original article. Attentive reader must have noticed that backPointC is shift in disguise. Here is the complete code. {-# LANGUAGE DeriveDataTypeable #-} module BackT where import Control.Monad.Trans import Control.Monad.Error import Control.Monad.Cont import Control.Exception import Data.Typeable data RestartMe = RestartMe deriving (Show, Typeable) instance Exception RestartMe instance Error SomeException -- Make a `restartable' exception -- (restartable from the beginning, that is) -- We redo the computation once we catch the exception RestartMe -- Other exceptions propagate up as usual. -- First, we use ErrorT backPoint :: Monad m = ErrorT SomeException m a - ErrorT SomeException m a backPoint m = catchError m handler where handler e | Just RestartMe - fromException e = backPoint m handler e = throwError e -- other errors propagate up test1 = runErrorT $ do lift $ print will not return back here backPoint $ do lift $ print will return here n2 - lift $ getLine lift $ print second input n3 - lift $ getLine if n3 == back then throwError (toException RestartMe) else lift $ print $ n2++n3 -- Obviously we can use error handling in the IO monad... -- Suppose we don't want backPoint that takes monad as argument. -- We wish backPoint that is a simple m () action. -- We will use Cont monad then: That is, we use Cont + Error Monad -- We reuse the old backPoint type BackT r m a = ContT r (ErrorT SomeException m) a backPointC :: Monad m = ContT e (ErrorT SomeException m) () backPointC = ContT (\k - backPoint (k ())) abort e = ContT(\k - e) test2 :: BackT r IO () test2 = do liftIO $ print will not return back here backPointC-- This line differs liftIO $ print will return here -- (and the indentation on here) n2 - liftIO $ getLine liftIO $ print second input n3 - liftIO $ getLine if n3 == back then abort $ throwError (toException RestartMe) else liftIO $ print $ n2++n3 test2r = runErrorT $ runContT test2 return ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Google Summer of Code - Lock-free data structures
Florian Hartwig wrote: Hi everyone, I would like to do the GSoC project outlined in http://hackage.haskell.org/trac/summer-of-code/ticket/1608 One of Haskell's great strengths is its support for all kinds of concurrent and parallel programmming, so I think that the Haskell ecosystem would benefit from having a wider range of efficient concurrent data structures. Also, more selfishly, I remember reading the article in CACM last summer and thinking that the whole idea of updating data structures directly using atomic compare-and-swap was really cool, so I would love to have an excuse to play around with it. Some (initial) ideas for lock-free data structures worth implementing: 1. A lock-free priority queue, e.g. using the approach based on skip-lists explained in [2] 2. Stacks, see [1] and [3] 3. Hash tables [4] but if anyone has other suggestions, I would obviously happy to hear them. Since I don't know much about concurrency, I have a simple question: what is the difference between atomic compare-and-swap and software transactional memory? Both are lock-free? Is it possible to implement every data structure based on CAS in terms of STM? What are the drawbacks? The other way round? Best 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] Google Summer of Code - Lock-free data structures
Though of course you can implement CAS in terms of STM, CAS is much more low-level and will probably be many times (though not asymptotically) faster. On Thu, Mar 29, 2012 at 12:01 PM, Heinrich Apfelmus apfel...@quantentunnel.de wrote: Florian Hartwig wrote: Hi everyone, I would like to do the GSoC project outlined in http://hackage.haskell.org/trac/summer-of-code/ticket/1608 One of Haskell's great strengths is its support for all kinds of concurrent and parallel programmming, so I think that the Haskell ecosystem would benefit from having a wider range of efficient concurrent data structures. Also, more selfishly, I remember reading the article in CACM last summer and thinking that the whole idea of updating data structures directly using atomic compare-and-swap was really cool, so I would love to have an excuse to play around with it. Some (initial) ideas for lock-free data structures worth implementing: 1. A lock-free priority queue, e.g. using the approach based on skip-lists explained in [2] 2. Stacks, see [1] and [3] 3. Hash tables [4] but if anyone has other suggestions, I would obviously happy to hear them. Since I don't know much about concurrency, I have a simple question: what is the difference between atomic compare-and-swap and software transactional memory? Both are lock-free? Is it possible to implement every data structure based on CAS in terms of STM? What are the drawbacks? The other way round? Best regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Eugene Kirpichov Principal Engineer, Mirantis Inc. http://www.mirantis.com/ Editor, http://fprog.ru/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] a code that cannot compile with or without NoMonomorphismRestriction
Ting Lei tin...@hotmail.com writes: (f1, f2) = let commond_definitions = undefined in let f1 = id.show f2 x = ( x) in (f1, f2) I think the type signatures should be: f1 :: Show a = a - String and f2 :: Ord b = b - b - Bool When I define these separately, this works: f1 :: Show a = a - String f1 = id . show f2 :: Ord b = b - b - Bool f2 = flip () But when I define them as a pair f1 :: Show a = a - String f2 :: Ord b = b - b - Bool (f1,f2) = (id . show, flip ()) I get an error message: Line 9: 1 error(s), 0 warning(s) Couldn't match expected type `forall a. Show a = a - String' with actual type `a - String' When checking that `f1' has the specified type `forall a1. Show a1 = a1 - String' Defining the pair at once works: p :: (Show a, Ord b) = (a - String, b - b - Bool) p = (id . show, flip ()) I guess that didn't help a lot, somebody with deeper GHC-fu than me will have to step in. -k -- If I haven't seen further, it is by standing in the footprints of giants ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Google Summer of Code - Lock-free data structures
On 29 March 2012 05:57, Ryan Newton rrnew...@gmail.com wrote: I just read in your proposal that you started looking into the casMutArray# issue as well. How far have you gotten with that? Do you want to work on this together a bit? I've got an implementation of a casArray# primop that passes a basic test, but I'm not sure if the GC write barrier is correct: https://github.com/rrnewton/ghc/commit/18ed460be111b47a759486677960093d71eef386 The write barrier is what I got stuck on as well. I don't know much about Haskell's GC. I'm going to read up on it, but my Master's project is due in in 3 weeks, so it's difficult to find the time right now. I'd be happy to work with you on this, but it'll probably have to wait until then. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Google Summer of Code - Lock-free data structures
On 29 March 2012 at 12:01 PM, Heinrich Apfelmus apfelmus at quantentunnel.de wrote: Since I don't know much about concurrency, I have a simple question: what is the difference between atomic compare-and-swap and software transactional memory? Both are lock-free? Well, terminology-wise it would probably be more accurate to say that you can implement lock-free algorithms using both (i.e. it's not really CAS and STM that are lock-free, but the algorithms implemented using them). But maybe this is a pedantic distinction. As to the difference between the two: CAS is just a machine instruction that takes an old expected value, a new value and an address and updates the memory pointed to by the address iff it contains the old/expected value. All this happens atomically, so you avoid the potential conflicts between threads concurrently reading from and writing to the same address. STM is much higher-level. It's an abstraction that allows the programmer to treat any sequence of reads and writes as a single atomic operation. This is, as the name says, implemented in software. So while the two are related, CAS is a machine primitive that works for a single operation and on a single word while STM is a software abstraction that isolates sequences of operations on multiple memory locations from each other. Is it possible to implement every data structure based on CAS in terms of STM? What are the drawbacks? The other way round? I think so. Atomically reading and writing a single memory location (which CAS does) is just a very simple transaction. But using a CAS instruction should be more efficient, since STM has to maintain a transaction log and commit transactions, which creates some overhead. I hope this makes some sense. Cheers, Florian ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] a code that cannot compile with or without NoMonomorphismRestriction
Ketil Malde wrote: Ting Lei tin...@hotmail.com writes: (f1, f2) = let commond_definitions = undefined in let f1 = id.show f2 x = ( x) in (f1, f2) I think the type signatures should be: f1 :: Show a = a - String and f2 :: Ord b = b - b - Bool When I define these separately, this works: f1 :: Show a = a - String f1 = id . show f2 :: Ord b = b - b - Bool f2 = flip () But when I define them as a pair f1 :: Show a = a - String f2 :: Ord b = b - b - Bool (f1,f2) = (id . show, flip ()) I get an error message: Line 9: 1 error(s), 0 warning(s) Couldn't match expected type `forall a. Show a = a - String' with actual type `a - String' When checking that `f1' has the specified type `forall a1. Show a1 = a1 - String' Defining the pair at once works: p :: (Show a, Ord b) = (a - String, b - b - Bool) p = (id . show, flip ()) I guess that didn't help a lot, somebody with deeper GHC-fu than me will have to step in. The problem is that f1 and f2 are polymorphic functions. To put polymorphic functions in a pair, you need *impredicative polymorphism*. Best 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] Google Summer of Code - Lock-free data structures
Florian Hartwig wrote: Heinrich Apfelmus wrote: So while the two are related, CAS is a machine primitive that works for a single operation and on a single word while STM is a software abstraction that isolates sequences of operations on multiple memory locations from each other. Is it possible to implement every data structure based on CAS in terms of STM? What are the drawbacks? The other way round? I think so. Atomically reading and writing a single memory location (which CAS does) is just a very simple transaction. But using a CAS instruction should be more efficient, since STM has to maintain a transaction log and commit transactions, which creates some overhead. Ah, I see. In that case, it may be worthwhile to implement the CAS instruction in terms of STM as well and measure the performance difference this makes for the final data structure. After all, STM is a lot more compositional than CAS, so I'd like to know whether the loss of expressiveness is worth the gain in performance. Best 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] Google Summer of Code - Lock-free data structures
On Thu, Mar 29, 2012 at 6:57 AM, Ryan Newton rrnew...@gmail.com wrote: The ByteArray versions will be more annoying, requiring more variations, but they are also less essential, because the user can always use ForeignPtr and bits-atomic in this case, and I believe for our concurrent data structures we want to store arbitrary pointers (hence casArray#). This is true, although using bits-atomic does a function call (i.e the calls are not inlined), which would be pretty bad for performance. G -- Gregory Collins g...@gregorycollins.net ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Google Summer of Code - Lock-free data structures
On Thu, Mar 29, 2012 at 9:01 AM, Gregory Collins g...@gregorycollins.netwrote: On Thu, Mar 29, 2012 at 6:57 AM, Ryan Newton rrnew...@gmail.com wrote: The ByteArray versions will be more annoying, requiring more variations, but they are also less essential, because the user can always use ForeignPtr and bits-atomic in this case, and I believe for our concurrent data structures we want to store arbitrary pointers (hence casArray#). This is true, although using bits-atomic does a function call (i.e the calls are not inlined), which would be pretty bad for performance. Yes, absolutely... I'd like to add the byte array versions. Actually, those don't have GC write barriers so they should be much easier to get right! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Google Summer of Code - Lock-free data structures
I think so. Atomically reading and writing a single memory location (which CAS does) is just a very simple transaction. But using a CAS instruction should be more efficient, since STM has to maintain a transaction log and commit transactions, which creates some overhead. Ah, I see. In that case, it may be worthwhile to implement the CAS instruction in terms of STM as well and measure the performance difference this makes for the final data structure. After all, STM is a lot more compositional than CAS, so I'd like to know whether the loss of expressiveness is worth the gain in performance. There's one annoying hitch with doing apples-to-apples comparisons here. The problem is that CAS falls short of being a hardware-accelerated version of a simple transaction (read TVar, (==) against expected value, conditionally update TVar), because CAS is based on pointer equality rather than true equality. (eq? rather than equal? for any Schemers out there.) For this reason our Fake version of CAS -- for older GHCs and for performance comparison -- has to use reallyUnsafePointerEquality#: http://hackage.haskell.org/packages/archive/IORefCAS/0.2/doc/html/Data-CAS-Internal-Fake.html But we do provide a CASable type class in that package which is precisely for comparing the performance of: - Hardware CAS - Fake CAS -- atomicModifyIORef + ptrEquality - Foreign CAS -- gcc intrinsic + function call Cheers, -Ryan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Google Summer of Code - Lock-free data structures
Hi, Somewhat related to this... Next month we have a paper coming up at EuroSys about a middle-ground between using STM and programming directly with CAS: http://research.microsoft.com/en-us/um/people/tharris/papers/2012-eurosys.pdf This was done in the context of shared memory data structures in C/C++, rather than Haskell. It might be interesting to see how the results carry over to Haskell, e.g. adding short forms of specialized transactions that interact correctly with normal STM-Haskell transactions. In the paper we have some examples of using short specialized transactions for the fast paths in data structures, while keeping the full STM available as a fall-back for expressing the cases that cannot be implemented using short transactions. --Tim -Original Message- From: haskell-cafe-boun...@haskell.org [mailto:haskell-cafe-boun...@haskell.org] On Behalf Of Heinrich Apfelmus Sent: 29 March 2012 13:30 To: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] Google Summer of Code - Lock-free data structures Florian Hartwig wrote: Heinrich Apfelmus wrote: So while the two are related, CAS is a machine primitive that works for a single operation and on a single word while STM is a software abstraction that isolates sequences of operations on multiple memory locations from each other. Is it possible to implement every data structure based on CAS in terms of STM? What are the drawbacks? The other way round? I think so. Atomically reading and writing a single memory location (which CAS does) is just a very simple transaction. But using a CAS instruction should be more efficient, since STM has to maintain a transaction log and commit transactions, which creates some overhead. Ah, I see. In that case, it may be worthwhile to implement the CAS instruction in terms of STM as well and measure the performance difference this makes for the final data structure. After all, STM is a lot more compositional than CAS, so I'd like to know whether the loss of expressiveness is worth the gain in performance. Best regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com ___ 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] adding the elements of two lists
From: Richard O'Keefe o...@cs.otago.ac.nz Date: Thu, 29 Mar 2012 16:34:46 +1300 On 29/03/2012, at 3:08 PM, Doug McIlroy wrote: - without newtype toSeries f = f : repeat 0 -- coerce scalar to series instance Num a = Num [a] where (f:fs) + (g:gs) = f+g : fs+gs (f:fs') * gs@(g:gs') = f*g : fs'*gs + (toSeries f)*gs' - with newtype newtype Num a = PS a = PS [a] deriving (Show, Eq) fromPS (PS fs) = fs -- extract list toPS f = PS (f : repeat 0) -- coerce scalar to series instance Num a = Num (PS a) where (PS (f:fs)) + (PS (g:gs)) = PS (f+g : fs+gs) (PS (f:fs)) * gPS@(PS (g:gs)) = PS $ f*g : fromPS ((PS fs)*gPS + (toPS f)*(PS gs)) Try it again. newtype PS a = PS [a] deriving (Eq, Show) u f (PS x)= PS $ map f x b f (PS x) (PS y) = PS $ zipWith f x y to_ps x = PS (x : repeat 0) ps_product (f:fs) (g:gs) = whatever instance Num a = Num (PS a) where (+) = b (+) (-) = b (-) (*) = b ps_product negate = u negate abs = u abs signum = u signum fromInteger = to_ps . fromInteger I've avoided defining ps_product because I'm not sure what it is supposed to do: the definition doesn't look commutative. You have given the Hadamard product--a construction with somewhat esoteric properties. The product I have in mind is the ordinary mathematical product that one meets in freshman calculus. The distributive law yields this symmetric formulation (f:fs) * (g:gs) = f*g : (toSeries f)*gs + fs*(toSeries g) + (0 : fs*gs) The version I gave is an optimization (which I learned from Jerzy). For more explanation see www.cs.dartmouth.edu/~doug/powser.html. I like the lifting functions b and u, but they don't get one very far. The product is where the PS pox begins to bite badly. I would welcome a perspicuous formulation of that using newtype. Incidentally, a more efficient way to write the symmetric product is (f:fs) * (g:gs) = f*g : zipWith (f*) gs + zipWith fs (*g) + (0 : fs*gs) toSeries and zipWith appear in the formulas because Haskell overloading won't let one use the multiplication symbol for both series*series and scalar*series. One might also invent a distinct operator for the purpose. Coercion with toSeries strikes me as the least jarring of these approaches. zipWith suffers from mixing levels of abstraction--it signifies not the idea of multiplication, but the algorithm. A new operator would suffer both from unfamiliarity and lack of commutativity. The code suffers a pox of PS. But it doesn't *need* to. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] a code that cannot compile with or without NoMonomorphismRestriction
I think the error message tell you how to fix: use -XNoMonomorphismRestriction One approach is add following line into top of your hs file and it works for me. {-# LANGUAGE NoMonomorphismRestriction #-} Regarding the deeper reason, I think you would be able to find via GHC user guide and google. -Haisheng On Thu, Mar 29, 2012 at 2:42 PM, Ting Lei tin...@hotmail.com wrote: Hi I have met a piece of code that cannot be compiled whether I add or remove the NoMonomorphismRestriction flag (as of GHC 7.0.4, Haskell platform 2011.4.0.0). I have extracted a minimal example below: {-# LANGUAGE NoMonomorphismRestriction #-} (f1, f2) = let commond_definitions = undefined in let f1 = id.show f2 x = ( x) in (f1, f2) I needed this format because there are many shared definitions in common_definitions for f1 and f2, and I want to keep them local. If I compile them with NoMonomorphismRestriction, I get: D:\work\test.hs:7:8: Ambiguous type variable `a0' in the constraint: (Show a0) arising from a use of `f1' Possible cause: the monomorphism restriction applied to the following: f1 :: a0 - String (bound at D:\work\hsOcaml\test.hs:2:2) Probable fix: give these definition(s) an explicit type signature In the expression: f1 In the expression: (f1, f2) In the expression: let f1 = id . show f2 x = ( x) in (f1, f2) D:\work\test.hs:7:12: Ambiguous type variable `a1' in the constraint: (Ord a1) arising from a use of `f2' Possible cause: the monomorphism restriction applied to the following: f2 :: a1 - a1 - Bool (bound at D:\work\hsOcaml\test.hs:2:6) Probable fix: give these definition(s) an explicit type signature In the expression: f2 In the expression: (f1, f2) In the expression: let f1 = id . show f2 x = ( x) in (f1, f2) Failed, modules loaded: none. If I comment out -- {-# LANGUAGE NoMonomorphismRestriction #-} I get: D:\work\hsOcaml\test.hs:4:17: Ambiguous type variable `a0' in the constraint: (Show a0) arising from a use of `show' Possible cause: the monomorphism restriction applied to the following: f1 :: a0 - String (bound at D:\work\hsOcaml\test.hs:2:2) Probable fix: give these definition(s) an explicit type signature or use -XNoMonomorphismRestriction In the second argument of `(.)', namely `show' In the expression: id . show In an equation for `f1': f1 = id . show D:\work\hsOcaml\test.hs:7:12: Ambiguous type variable `a1' in the constraint: (Ord a1) arising from a use of `f2' Possible cause: the monomorphism restriction applied to the following: f2 :: a1 - a1 - Bool (bound at D:\work\hsOcaml\test.hs:2:6) Probable fix: give these definition(s) an explicit type signature or use -XNoMonomorphismRestriction In the expression: f2 In the expression: (f1, f2) In the expression: let f1 = id . show f2 x = ( x) in (f1, f2) Failed, modules loaded: none. Can anyone show me why this does not work and how to fix it (e.g. by adding type signature as the error message suggested)? I tried to add type signature by couldn't figure out the right way of doing it. Thanks in advance! Ting ___ 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] a code that cannot compile with or without NoMonomorphismRestriction
Ketil, Thanks for the response. It seems that defining them as a pair only postphones the error.GHC will give an error when you extract the components of the pair, no matter whether you addthe NoMonomorphismRestriction flag or not. --{-# LANGUAGE NoMonomorphismRestriction #-}p :: (Show a, Ord b) = (a - String, b - b - Bool) p = (id . show, flip ())f1 = fst p f2 = snd p---Without NoMonomorphismRestriction, I got: D:\work\test1.hs:6:10: Ambiguous type variable `a0' in the constraint: (Show a0) arising from a use of `p' Possible cause: the monomorphism restriction applied to the following: f1 :: a0 - String (bound at D:\work\hsOcaml\test1.hs:6:1) Probable fix: give these definition(s) an explicit type signature or use -XNoMonomorphismRestriction In the first argument of `fst', namely `p' In the expression: fst p In an equation for `f1': f1 = fst pD:\work\hsOcaml\test1.hs:6:10: Ambiguous type variable `b0' in the constraint: (Ord b0) arising from a use of `p' Probable fix: add a type signature that fixes these type variable(s) .. Failed, modules loaded: none. --With NoMonomorphismRestriction, I got: D:\work\test1.hs:6:10: Ambiguous type variable `b0' in the constraint: (Ord b0) arising from a use of `p' Probable fix: add a type signature that fixes these type variable(s) In the first argument of `fst', namely `p' In the expression: fst p In an equation for `f1': f1 = fst pD:\work\test1.hs:7:10: Ambiguous type variable `a0' in the constraint: (Show a0) arising from a use of `p' Probable fix: add a type signature that fixes these type variable(s) In the first argument of `snd', namely `p' In the expression: snd p In an equation for `f2': f2 = snd p Failed, modules loaded: none. Thanks, Ting From: ke...@malde.org To: tin...@hotmail.com CC: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] a code that cannot compile with or without NoMonomorphismRestriction Date: Thu, 29 Mar 2012 12:27:04 +0200 Ting Lei tin...@hotmail.com writes: (f1, f2) = let commond_definitions = undefined in let f1 = id.show f2 x = ( x) in (f1, f2) I think the type signatures should be: f1 :: Show a = a - String and f2 :: Ord b = b - b - Bool When I define these separately, this works: f1 :: Show a = a - String f1 = id . show f2 :: Ord b = b - b - Bool f2 = flip () But when I define them as a pair f1 :: Show a = a - String f2 :: Ord b = b - b - Bool (f1,f2) = (id . show, flip ()) I get an error message: Line 9: 1 error(s), 0 warning(s) Couldn't match expected type `forall a. Show a = a - String' with actual type `a - String' When checking that `f1' has the specified type `forall a1. Show a1 = a1 - String' Defining the pair at once works: p :: (Show a, Ord b) = (a - String, b - b - Bool) p = (id . show, flip ()) I guess that didn't help a lot, somebody with deeper GHC-fu than me will have to step in. -k -- If I haven't seen further, it is by standing in the footprints of giants ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Is this a correct explanation of FRP?
Hi, I've been trying to get my head around Functional Reactive Programming by writing a basic explanation of it, following the logic that explaining something is the best way to understand it. Am I on the right track with this explanation? Greetings, Peter Minten P.S. Sorry about the long mail, the explanation ended up a little longer than I originally expected. :) Document (with markdown formatting) follows: --8--8--8--8--8--8--8--8--8--8--8--8--8--8--8--8-- This is an attempt to explain Functional Reactive Programming (FRP) enough to give a reader with no previous exposure to FRP an intuition what FRP is about. After reading this you should hopefully understand enough of FRP to understand the [reactive-banana](http://www.haskell.org/haskellwiki/Reactive-banana) examples. FRP has certain terms such as behavior, event and time-varying that can be confusing for people unfamiliar with it. I'll avoid these terms at first and will focus on spreadsheets and a generalization of spreadsheet cells (which I will call boxes). Later, once the most important concepts are explained, reactive-banana syntax will be introduced along with an example that demonstrates how to work with behaviors and events in reactive-banana. Finally some theory about time-varying functions and how events and behaviors can be implemented using pure functions by making time explicit should provide the necessary background to understand reactive-banana's haddock comments. The version of reactive-banana used here is [0.5.0.0](http://hackage.haskell.org/package/reactive-banana-0.5.0.0). Reactive Programming for the Masses: The Spreadsheet Spreadsheets are something we all (for certain values of we) know about. Let's talk about a typical, simplified, spreadsheet. We have a list of products that we sell and want to compute their price with the Value Added Tax (VAT) added. We might have cells A1 to A10 contain the raw prices of our products and cell B1 contain the current VAT rate (say 19 for a 19% VAT). In cells C1 to C10 we'd like to see the prices including VAT. In cell C1 we'd have a formula: `=A1*(1+B1/100)`, in cell C2 `=A2*(1+B1/100)`, etc. So if A1 contains $100 C1 would contain $119. But what if the government, in it's eternal quest to reduce the budget deficit, raises the VAT rate? We'd adjust cell B1, just change it to 20. And like magic all the C cells are updated. Though this may seem mundane what we've just seen is actually a very good example of reactive programming. We didn't tell the C cells to update; they updated on their own because a value they depend on changed. From Cells to Boxes: Generalizing the Spreadsheet = Spreadsheets are nice, but if we want to truly get a feel for FRP we'll have to think beyond them. If we look at a spreadsheet at an abstract level it pretty much consists of cells of two types: value cells (`19`) and formula cells (`=A1*(1+B1/100)`). Let's lose the reference to spreadsheets and talk about boxes. Say, for now, that there are two kinds of boxes: formula boxes and value boxes. Both support a get operation that returns a value. Value boxes additionally support a set operation that sets the value. Formula boxes can contain any kind of pure function. They can also refer to the values of other boxes (both formula and value boxes). Value boxes don't have a function inside them, they have a value. The translation of our VAT spreadsheet would be something like a formula box *fIncl1* containing the expression `get(vExcl1) * (1 + get(vVat) / 100)`. This expression uses two value boxes: *vExcl1* and *vVat*. We could also write *fIncl1* using a helper formula box *fVat*. Let *fVat* have the formula `1 + get(vVat) / 100` and *fIncl1* have the formula `get(vExcl1) * get(vVat)`. I'll use `:=` for this kind of definition, the `:=` is there to remind you that this isn't Haskell. It's important to note that any kind of value may be put into value boxes, including IO actions and functions. Try doing this with a spreadsheet: `fIncls := [get(ve) * get(vVat) | ve - vExcls]`. Or this: `fIncl1 := apply(get(vVatFunc), get(vExcl1))`. If you're wondering why I'm not using Haskell syntax, it's to focus on the meaning of boxes rather than what the functions and combinators mean. That said, this pseudo-imperative syntax is on its way out as it's getting too clunky (that `apply` function is really just ugly). For a quick peek ahead the last few examples would be something like this in reactive-banana: fIncls = map (\ve - (*) $ ve * fVat) vExcls fIncl1 = fVatFunc * vExcl1 Events == Let's say we want to build the worlds worst synthesizer. We have 7 buttons: a, b, c, d, e, f and g. Our output is generated by sampling a box twice per second and playing the frequency in the box until the next sample is taken. This can't be expressed with the crude formula and value boxes system we've had so far.
Re: [Haskell-cafe] Mathematics and Statistics libraries
Hey All, Theres actually a number of issues the come up with an effective dataframe-like for haskell, and data vis as well. (both of which I have some strong personal opinions on for haskell and which I'm exploring / experimenting with this spring). While folks have touched on a bunch, I just thought I'd put together my own opinions in the mix. First of all: any good data manipulation (i.e. data frame -like ) library needs support for efficiently querying subsets of the data in various ways. Not just that, it really should provide coherent way of dealing with out of core data! From there you might want to ask the question: do I want to iterate through chunks of the data or do i want to allow more general patterns of data access, and perhaps even ways to parallelize?. The basic thing (as others have remarked after this draft email got underway), you do essentially want to support some sql-like selection operations, and have them be efficient too, along with playing nice with columns of differing types What sort of abstractions you provide are somewhat crucial, because that in turn affects how you can write algorithms! If you look closely, this is tantamount to saying that any sufficiently well designed (industrial grade) data frame lib for haskell might wind up leading into a model for supporting mapreduce or graphlab http://graphlab.org/ style algorithms in the multicore / not distributed regime, though a first version would pragmatically just provide an interface with sequentially chunked data and use pipes-core, or one of the other enumerator libraries. Theres also some need for the aforementioned fancy types for managing data, but that not even the real challenge (in my opinion). Probably the best lib to take ideas from is the python Pandas library, or at least thats my personal opinion. Now in the space of data vis, probably the best example of a good library in terms of easy of getting informative (and pretty) outputs is ggplot2 (also in R). Now if you look there, you'll see that its VERY much integrated with the model fitting and data analysis functionality of R, and has a very compositional approach which could easily be ported pretty directly over to haskell. However, as with a good data frame-like, certain obstacles come up partly because if we insist a type safe way to do things while being at least as high level as R or python, the absence of row types for frame column names makes specifying linear models that are statically well formed (as in only referencing column names that are actually in the underlying data frame) bit tricky, and while there are approaches that do work some of the time, theres not really a good general purpose way (as far as I can tell) for that small problem of trying to resolve names as early as possible. Or at the very least I don't see a simple approach that i'm happy with. these can be summarized I think as follows: Any practical data frame lib needs to interact well with out of core data, and ideally also simplify the task of writing algorithms on top in a way that sort of gives out of core goodness for free. Theres a lot of different ways this can be perhaps done under the covers, perhaps using one of the libraries like reducers, enumerator or pipes core, but it really should be invisible for the client algorithms author, or at least invisible by default. And more over I think any attack in that direction is essentially a precursor to sorting out map-reduce and graph lab like tools for haskell. Any really nice high level data vis tool really needs to have some data analysis / machine learning style library that its working with, and this is probably best understood by looking at things already out there, such as ggplot2 in R that said, I'm all ears for other folks takes on this, especially since I'm spending some time this spring experimenting in both these directions. cheers -Carter On Sun, Mar 25, 2012 at 9:54 AM, Aleksey Khudyakov alexey.sklad...@gmail.com (mailto:alexey.sklad...@gmail.com) wrote: On 25.03.2012 14 (tel:25.03.2012%2014):52, Tom Doris wrote: Hi Heinrich, If we compare the GHCi experience with R or IPython, leaving aside any GUIs, the help system they have at the repl level is just a lot more intuitive and easy to use, and you get access to the full manual entries. For example, compare what you see if you type :info sort into GHCi versus ?sort in R. R gives you a view of the full docs for the function, whereas in GHCi you just get the type signature. Ingrating haddock documentation into GHCi would be really helpful but it's GSoC project on its own. For me most important difference between R's repl and GHCi is that :reload wipes all local binding. Effectively it forces to write everything in file and to avoid doing anything which couldn't be fitted into one-liner. It may not be bad but it's definitely different style And of course data visualization.
Re: [Haskell-cafe] adding the elements of two lists
On 29 March 2012 04:34, Richard O'Keefe o...@cs.otago.ac.nz wrote: u f (PS x)= PS $ map f x b f (PS x) (PS y) = PS $ zipWith f x y to_ps x = PS (x : repeat 0) Also see: http://hackage.haskell.org/package/newtype -- Ozgur Akgun ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ANN: Happstack 7
We are pleased to announce the release of Happstack 7! Happstack is a fast, modern, web application framework written in Haskell. Please check out the brand new happstack.com website to read about what is new in Happstack 7, and what we are planning for Happstack 8, and what makes Happstack great! http://www.happstack.com/ - jeremy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] for = flip map
Some more bikeshedding: Perhaps ffor, as in ffor = flip fmap or perhaps infixr 0 $$ ($$) = flip ($) xs $$ \x - ... (cf. **) In both cases they should go in Data.Functor Sjoerd On Mar 28, 2012, at 11:26 PM, e...@ezrakilty.net wrote: I would very much like to see a standard function for flip map along these lines. I think it would make a lot of code more readable. Like the OP, I use for in my own code. It's unfortunate that Data.Traversable takes the name with another type. Two options would be to (a) reuse the name in Data.List and force people to qualify as necessary, or (b) choose another name for flip map. Regarding other possible names: forall is a keyword and forAll is used by QuickCheck. One possibility would be foreach. Ezra On Wed, Mar 28, 2012, at 10:19 PM, Christopher Done wrote: On 28 March 2012 22:05, Matthew Steele mdste...@alum.mit.edu wrote: Doesn't for already exist, in Data.Traversable? Except that for = flip traverse. Traverse doesn't fit the type of fmap, it demands an extra type constructor: traverse :: (Traversable t,Applicative f) = (a - f b) - t a - f (t b) fmap :: Functor f = (a - b) - f a - f b Note the (a - f b) instead of (a - b). E.g. fmap :: (a - b) - [a] - [b] can't be expressed with traverse, you can only get this far: traverse :: (a - [b]) - [a] - [[b]] Unless I'm missing something. ___ 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 -- Sjoerd Visscher https://github.com/sjoerdvisscher/blog ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] winhugs interrupts
On Wed, 28 Mar 2012 22:42:58 +0200, Doug McIlroy d...@cs.dartmouth.edu wrote: On windows I have long used hugs under cygwin, but hugs doesn't get along well with cygwin's latest terminal emulator. So I switched to winhugs. Small problem that looms big: how do you interrupt an interminable expression evaluation in winhugs? Select menu Action - Stop Regards, Henk-Jan van Tuyl -- http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming -- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] for = flip map
On 29 March 2012 22:03, Sjoerd Visscher sjo...@w3future.com wrote: Some more bikeshedding: Perhaps ffor, as in ffor = flip fmap or perhaps infixr 0 $$ ($$) = flip ($) xs $$ \x - ... I don't think it makes sense to add a whole new operator for that. You can just use sections: ($ xs) \x - ... The reason you can't do this with * is the ordering of effects. I have to admit, though, that the above isn't exactly readable. The non-operator version is somewhat more readable: (`map` xs) \x - ... I'd still prefer for or foreach. (cf. **) In both cases they should go in Data.Functor Sjoerd On Mar 28, 2012, at 11:26 PM, e...@ezrakilty.net wrote: I would very much like to see a standard function for flip map along these lines. I think it would make a lot of code more readable. Like the OP, I use for in my own code. It's unfortunate that Data.Traversable takes the name with another type. Two options would be to (a) reuse the name in Data.List and force people to qualify as necessary, or (b) choose another name for flip map. Regarding other possible names: forall is a keyword and forAll is used by QuickCheck. One possibility would be foreach. Ezra On Wed, Mar 28, 2012, at 10:19 PM, Christopher Done wrote: On 28 March 2012 22:05, Matthew Steele mdste...@alum.mit.edu wrote: Doesn't for already exist, in Data.Traversable? Except that for = flip traverse. Traverse doesn't fit the type of fmap, it demands an extra type constructor: traverse :: (Traversable t,Applicative f) = (a - f b) - t a - f (t b) fmap :: Functor f = (a - b) - f a - f b Note the (a - f b) instead of (a - b). E.g. fmap :: (a - b) - [a] - [b] can't be expressed with traverse, you can only get this far: traverse :: (a - [b]) - [a] - [[b]] Unless I'm missing something. ___ 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 -- Sjoerd Visscher https://github.com/sjoerdvisscher/blog ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Push the envelope. Watch it bend. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Google Summer of Code - Lock-free data
Slightly related: I think it would be interesting to compare a Disruptor-based concurrency communications mechanism and compare it to e.g. TChans 1. Disruptor - http://code.google.com/p/disruptor/ From: Ryan Newton rrnew...@gmail.com I think so. Atomically reading and writing a single memory location (which CAS does) is just a very simple transaction. But using a CAS instruction should be more efficient, since STM has to maintain a transaction log and commit transactions, which creates some overhead. Ah, I see. In that case, it may be worthwhile to implement the CAS instruction in terms of STM as well and measure the performance difference this makes for the final data structure. After all, STM is a lot more compositional than CAS, so I'd like to know whether the loss of expressiveness is worth the gain in performance. There's one annoying hitch with doing apples-to-apples comparisons here. The problem is that CAS falls short of being a hardware-accelerated version of a simple transaction (read TVar, (==) against expected value, conditionally update TVar), because CAS is based on pointer equality rather than true equality. (eq? rather than equal? for any Schemers out there.) For this reason our Fake version of CAS -- for older GHCs and for performance comparison -- has to use reallyUnsafePointerEquality#: http://hackage.haskell.org/packages/archive/IORefCAS/0.2/doc/html/Data-CAS-Internal-Fake.html But we do provide a CASable type class in that package which is precisely for comparing the performance of: - Hardware CAS - Fake CAS -- atomicModifyIORef + ptrEquality - Foreign CAS -- gcc intrinsic + function call ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Is this a correct explanation of FRP?
Peter Minten peter.min...@orange.nl wrote: I've been trying to get my head around Functional Reactive Programming by writing a basic explanation of it, following the logic that explaining something is the best way to understand it. Am I on the right track with this explanation? You are explaining a particular instance of FRP. Functional reactive programming is not a single concept, but a whole family of them. Traditional FRP as implemented by reactive-banana (and older libraries like Elerea, Fran and Reactive) is based on behaviors and events. It uses the notion of a time-dependent value in a direct fashion. Conceptionally traditional FRP is this: Behavior a = Time - a Event a= [(Time, a)] -- The current time at even seconds and half the current time at odd -- seconds: alterTime = fullTime fullTime = switch (after 1) currentTime halfTime halfTime = switch (after 1) (fmap (/ 2) currentTime) fullTime There is a second instance of FRP though called AFRP. The A stands for arrowized, but in modern times I prefer to think of it as applicative. The underlying control structure is now a category and the concept of a time-varying value is changed to a time-varying function (called signal function (SF)), which is just an automaton and there is an arrow for it. This simplifies implementation, makes code more flexible and performance more predictable. The libraries Animas and Yampa implement this concept (Animas is a fork of Yampa). Conceptionally: SF a b= a - (b, SF a b) Event a b = SF a (Maybe b) alterTime = fullTime fullTime = switch (after 1) currentTime halfTime halfTime = switch (after 1) ((/ 2) ^ currentTime) fullTime Now both the predefined event function 'after' and the predefined signal 'currentTime' are signal functions. It also allows to implement some analysis tools easily: -- Emit an event whenever the given signal function's output -- changes: changesOf :: (Eq b) = SF a b - SF a (Maybe b) Finally there is an extension of AFRP of which I'm the proud inventor. =) By generalizing the automaton arrow to allow what I call signal inhibition you get to the wire arrow. This adds another layer of flexibility, unifies the notions of time-varying functions and events and completely removes the need for switching. Events can now be handled implicitly. The library Netwire implements this concept. Conceptionally: Wire a b = a - (Maybe b, Wire a b) Event = Wire changesOf :: (Eq b) = Wire a b - Wire a b alterTime = fullTime | halfTime fullTime = when (even . floor) . time halfTime = fmap (/ 2) time Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife = sex) http://ertes.de/ signature.asc Description: PGP signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] How helpful is h-99 (and should we complete the missing ones)?
Hi all, I am new at Haskell, but I am trying to learn as much as possible. While learning, I noticed that h-99 (the 99 Haskell problems) are highly recommended on haskell.org. However, the answers to the 99 problems are not finished, and some of the answers are not really Haskell-ish. So here's my question: how useful is h-99 (are they overrated as learning tools)? I find myself solve most of them in a from the scratch fashion (e.g., no Monad, no Applicative, no Functor aside from List and a few Maybe). Some of them are paper-worthy, for example the prime problems. I hope some guru-level Haskeller could do away the missing few, and maybe dive deeper into the surface to produce more insights (like the knights travel page or the sieve paper, which are both beautiful). And of course, if anyone could tell me how to learn Haskell without treating it as just another functional language, I'd be very grateful:) Thanks, Ziyao ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe