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] Mapping string to a function
Thanks Oliver. That's good enough. I was ever curious about whether parse String to the function rather than a mapping. -Haisheng On Thu, Mar 15, 2012 at 1:26 PM, Oliver Batchelor saul...@gmail.com wrote: You could store your test data in a named map e.g. import qualified Data.Map as M import System testSets :: M.Map String [Int] testSets = M.fromList [ (testdata, testdata) , (testdata2, testdata2) ] f :: Int - Something f = main = do [arg] - getArgs case M.lookup arg testSets of Just testSet - print (map f testSet) Nothing - print Test set not found! On Thu, Mar 15, 2012 at 12:59 PM, Haisheng Wu fre...@gmail.com wrote: Hi there, Do you have any comments / suggestions for the following scenario? I have two list and a function over list testdata :: [Int] testdata2 :: [Int] f testdata = map g testdata What I like to do is choosing what test data via command line arguments. i.e. test.hs testdata2 will run against testdata2 I could make it using pattern match between argument and data definition but it is annoy. code here: https://github.com/freizl/dive-into-haskell/blob/master/sandbox/one-in-arith-seq.hs I'm wondering it can be done simply in haskell. Thanks a lot. -Haisheng ___ 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] Mapping string to a function
Hi there, Do you have any comments / suggestions for the following scenario? I have two list and a function over list testdata :: [Int] testdata2 :: [Int] f testdata = map g testdata What I like to do is choosing what test data via command line arguments. i.e. test.hs testdata2 will run against testdata2 I could make it using pattern match between argument and data definition but it is annoy. code here: https://github.com/freizl/dive-into-haskell/blob/master/sandbox/one-in-arith-seq.hs I'm wondering it can be done simply in haskell. Thanks a lot. -Haisheng ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Problem resolving: Hangman
Though the problem I'd ask is not quiet related to haskell, I hope talent people here could provide some suggestions. The problem is not just solve the Hangman problem but solve it in sort of AI way. General idea is : 1. Randomly pick words, e.g. 20 from a predefined word list file. ( http://www.word-list.com/) 2. The application play hangman with each word till either WON or FAIL. NO human being interactive. 3. The expect result is the application be able to win the game at most of time before a certain max wrong guess, e.g. 5 Please let me where is a better place to ask such question and thank you so much in advance. -Simon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Rewrite this imperative in FP way
The reason I redefined Eq is: When doing `union` over two list of MyTuple is just base on its first element. Basically it means: [(1,2), (2,2)] `union` [(1,0), (2,0), (0,0)] produce [(1,2), (2,2), (0,0)] rather than [(1,2),(2,2),(1,0),(2,0),(0,0)] by default. -Haisheng On Sun, Feb 5, 2012 at 11:37 PM, Yves Parès yves.pa...@gmail.com wrote: Concerning your first solution, I don't understand why you redefine Eq but not Ord instance. Ord will still work by comparing the tuples and not the first elements of said tuples. Plus the good news is you don't have to do this: just use regular tuples and use sort*By *or group*By *functions from Data.List with the 'on' function from Data.Function. For instance your Eq instance could have been written x == y = (==) `on` (fst . getTuple) With regular tuples you can write sortBy (compare `on` fst). Plus can you rewrite your original imperative algorithm with the right variable names? You're using a 'd' array that's not been defined. 2012/2/5 Haisheng Wu fre...@gmail.com a = [1,1,1,1] b = [0,1,2,3] d = [0,0,0,0] for i in b: for j in c: if (i+j)3: d[i+j] += a[i] My just work implementation in Haskell http://hpaste.org/57452 Another people implementation in Haskell with Monad and it turns out complex and very imperatively. http://hpaste.org/57358 Do you have any cool solution in FP way? Thanks. -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] Rewrite this imperative in FP way
*d = [sum $ map (a !!) [i | i - b, j - c, i + j 3, i + j == dIndex] | dIndex - [0..3]] * This is cool. -Simon On Sun, Feb 5, 2012 at 5:07 PM, L Corbijn aspergesoe...@gmail.com wrote: On Sun, Feb 5, 2012 at 7:28 AM, Haisheng Wu fre...@gmail.com wrote: a = [1,1,1,1] b = [0,1,2,3] d = [0,0,0,0] for i in b: for j in c: if (i+j)3: d[i+j] += a[i] My just work implementation in Haskell http://hpaste.org/57452 Another people implementation in Haskell with Monad and it turns out complex and very imperatively. http://hpaste.org/57358 Do you have any cool solution in FP way? Thanks. -Simon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe There are several ways to make it nicer. Without assumption on what lists a, b and c contain it can be written as d = [sum $ map (a !!) [i | i - b, j - c, i + j 3, i + j == dIndex] | dIndex - [0..3]] With the assumption that b and c are both [0..3] this can be 'improved' to d = (take 3 . map sum . tail $ inits a) ++ replicate (4 - 3) 0 This generates the first three values by the complicated expression and then adds the extra zero's by using the replicate expression. This works as the value of the i-th element of d is the sum over the first i elements in a if i 3 and 0 otherwise. A list of lists with the first i elements is generated with 'tail $ inits a' which is then summed and restricted to length 3. An alternative for this is d = (take 3 . snd $ mapAccumL (\acc ai - (acc + ai, acc + ai)) 0 a) ++ replicate (4 - 3) 0 Where the summation and tail generating is done in the mapAccumL function. Greetings, Lars P.S. Yes the replicate (4-3) 0 can be replaced by [0], but I wanted to explicitly include the length (4) of the expected list. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Rewrite this imperative in FP way
Sorry there is a mistake in the problem description. Here it is in Python: a = [1,1,1,1] b = [0,1,2,3] c = [0,2] d = [0,0,0,0] for i in b: for j in c: if (i+j)3: d[i+j] += a[i] -Haisheng On Sun, Feb 5, 2012 at 2:28 PM, Haisheng Wu fre...@gmail.com wrote: a = [1,1,1,1] b = [0,1,2,3] d = [0,0,0,0] for i in b: for j in c: if (i+j)3: d[i+j] += a[i] My just work implementation in Haskell http://hpaste.org/57452 Another people implementation in Haskell with Monad and it turns out complex and very imperatively. http://hpaste.org/57358 Do you have any cool solution in FP way? Thanks. -Simon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Rewrite this imperative in FP way
a = [1,1,1,1] b = [0,1,2,3] d = [0,0,0,0] for i in b: for j in c: if (i+j)3: d[i+j] += a[i] My just work implementation in Haskell http://hpaste.org/57452 Another people implementation in Haskell with Monad and it turns out complex and very imperatively. http://hpaste.org/57358 Do you have any cool solution in FP way? Thanks. -Simon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How hard is it to start a web startup using Haskell?
Turns out that those guys doing start-up with Haskell are already expert at Haskell. Hence choosing Haskell is more straightforward. I'm thinking of using Haskell since it looks cool and beautiful. However I have little experience and will move slowly at certain begging period. This sounds not good to a startup company. Comparing with Django in Python, Rails in Ruby, yesod and snap looks not that mature. Also, for instance, I'd like to build up a CRM application company, I could leverage some open source projects in other languages. In Haskell, we need to build from scratch basically. Appreciate your suggestions/comments. -Simon On Wed, Dec 21, 2011 at 2:30 AM, David Pollak feeder.of.the.be...@gmail.com wrote: On Mon, Dec 19, 2011 at 2:36 PM, Yves Parès limestr...@gmail.com wrote: Haskell is a mature platform that provides lots of goodies that I might otherwise have to write (like the goodies I wrote in Lift including an Actors library) I don't get it: Actors are at the core of Scala concurrency model, Actors as implemented in the Scala distribution were (and probably still are) horrid. They have poor performance, memory retention issues, and an overall poor design. When Lift relied on Scala's Actors, a Lift-comet site needed to be restarted every few weeks because of pent-up memory issues. On the other hand, with Lift Actors, http://demo.liftweb.net has been running since July 7th. and are expanded for distributed programming through Akka for instance. Actually, no. Scala's Actors are not expanded by Akka (although Akka Actors may replace the existing Actor implementation in the Scala library). Akka is yet another replacement for Scala's Actor library and Akka's distributed capabilities are weak and brittle. Also, Lift's Actor library and Martin Odersky's flames about it paved the way for Akka because I took the heat that might have driven Jonas out of the Scala community when Akka was a small project. To me it'd be the other way around: you'd have to develop Actors in Haskell, don't you? I've come to understand that Actors are a weak concurrency/distribution paradigm. Anything that has a type signature Any = Unit is not composable and will lead to the same kinds of issues that we're looking for the compiler in Haskell to help us with (put another way, if you like Smalltalk and Ruby, then Actors seem pretty cool.) On the other hand, many of Haskell's libraries (STM, Iteratees, etc.) have a much more composable set of concurrency primitives. Or maybe you don't mean the same thing by 'Actor'? 2011/12/19 David Pollak feeder.of.the.be...@gmail.com On Mon, Dec 19, 2011 at 2:04 AM, Ivan Perez ivanperezdoming...@gmail.com wrote: I'm actually trying to make a list of companies and people using Haskell for for-profit real world software development. I'd like to know the names of those startups, if possible. I am building http://visi.pro on Haskell. I am doing it for a number of reasons: - Haskell is a mature platform that provides lots of goodies that I might otherwise have to write (like the goodies I wrote in Lift including an Actors library) - Haskell allows a lot of nice things that make building a language and associated tools easier (like laziness) - Haskell is a filter for team members. Just like Foursquare uses Scala as a filter for candidates in recruiting, I'm using Haskell as a filter... if you have some good Haskell open source code, it's a way to indicate to me that you're a strong developer. -- Ivan On 18 December 2011 18:42, Michael Snoyman mich...@snoyman.com wrote: On Sun, Dec 18, 2011 at 6:57 PM, Gracjan Polak gracjanpo...@gmail.com wrote: Hi all, The question 'How hard is it to start a technical startup with Haskell?' happened a couple of times on this list. Sometimes it was in the form 'How hard is to find Haskell programmers?' or 'Are there any Haskell jobs?'. I'd like to provide one data point as an answer: http://www.reddit.com/r/haskell/comments/ngbbp/haskell_only_esigning_startup_closes_second_angel/ Full disclosure: I'm one of two that founded this startup. How are others doing businesses using Haskell doing these days? I don't run a startup myself, but I know of at least three startups using Haskell for web development (through Yesod), and my company is basing its new web products on Yesod as well. I think there are plenty of highly qualified Haskell programmers out there, especially if you're willing to let someone work remotely. Michael ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Visi.Pro, Cloud Computing for the Rest of Us
Re: [Haskell-cafe] [Haskell-beginners] Int V.S. Word32
Hmm... I think I made a little confusion so I put my finding here: http://haisgwu.info/posts/2011-11-20-euler-problem-14.html I do got stack overflow thus need several compile opts to fix it. Not sure if it is what you mean by You get overflow using 32-bit types here. -Haisheng On Sat, Nov 19, 2011 at 10:49 PM, Daniel Fischer daniel.is.fisc...@googlemail.com wrote: On Saturday 19 November 2011, 09:09:50, Haisheng Wu wrote: Hello, I got great performance difference for the following code if I used type `Int` rather than `Data.Word.Word32`. Anyone can help to explain why such difference? Short answer: GHC optimises Int calculations far better than Word32 calculations, rather, it optimises more calculations for Int than for Word32. It also optimises more calculations for Word than for Word32, but not as many as for Int. The reason is that Int (and Word) are (at least expected to be) far more often used, so the effort has gone to these types primarily. Work is being done to get the fixed-width types on par, but it's not around the corner yet. You can try using Word instead of Word32, that's likely to be faster. But Thanks a lot. -Simon module Main where import Data.Word main :: IO () main = print $ p14 p14 = maximum [ (startChain n 0, n) | n - [2..100] ] You get overflow using 32-bit types here. startChain :: Word32 - Int - Int startChain 1 count= count + 1 startChain n count= startChain (intTransform n) (count+1) intTransform :: Word32 - Word32 intTransform n | even n = n `div` 2 | otherwise = 3 * n + 1 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Real CMS Application in Haskell
It's being great than those frameworks getting popular and mature. Initially what I expect is something similar toJoomla! in PHP or Refinery CMS in Ruby than allow us to quick start a CMS application. And I'm not such experienced at Haskel to build a one on my own. :( Thanks. -Haisheng On Sun, Sep 4, 2011 at 2:02 PM, Michael Snoyman mich...@snoyman.com wrote: On Sun, Sep 4, 2011 at 8:46 AM, Haisheng Wu fre...@gmail.com wrote: Hello guys, I googled for a real open source CMS application in Haskell but have no luck. So I'm wondering if Haskell is used very little in Web development area. Thanks. -Simon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe The Yesod site itself[1] is basically a CMS application, depending on your definition. It's a product that my company[2] is working on to address needs of large organizations in creating both structured and community-enhanced documentation. (More information available if anyone's interested...) That said, I wouldn't judge a community based on the presence or absence of a single application. The fact that there are three active frameworks (Yesod, Happstack, Snap) that all seem to be growing in popularity says more than the fact that my company is writing a CMS. Michael [1] http://www.yesodweb.com/ [2] http://www.suite-sol.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Real CMS Application in Haskell
Hello guys, I googled for a real open source CMS application in Haskell but have no luck. So I'm wondering if Haskell is used very little in Web development area. Thanks. -Simon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Any good topics for Master Thesis
Dear Haskellers, I'm a master student major of computer science and trying to find any topics for my master thesis. My mentor suggest me to find any topic I'm interested in. Therefore I'm thinking whether there are some topics related to FP and Haskell. Especially use such technology to solve problems rather than theory research. Appreciate any suggestions / ideas! -Simon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] How to use Yesod OAuth
Hello, I'm trying to use Yesod oAuth plugin to a SNS site which is very similar to Twitter. I add oAuth into the authPlugin and I'm able to see the auth URL at login page. I click the URL and it forwards me to a page ask me input that SNS site account. I fill in my account then the browser navigate to the authorize page display a authorised code (8 digits). Then, how I suppose to continue? (I think this is the 2nd phase of the oauth process) I expect there will be a text box in my App where I can fill in the authorised code. Or even the oAuth plugin automatically get the authorised code and continue to the next oauth phase. Appreciate your help! Haisheng ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe