Re: [Haskell-cafe] Mapping string to a function
On Thu, Mar 15, 2012 at 02:21, Haisheng Wu wrote: > Thanks Oliver. That's good enough. > I was ever curious about whether parse String to the function rather > than a mapping. > GHC has the ability to embed an interpreter. You do not want to use it. If you want Perl/Python/Ruby, please use those; they are interpreters and have built-in embedded interpreters for use by programs. (Note that C and C++ are not generally interpreted and also don't have embedded interpreters either.) -- brandon s allbery allber...@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms ___ 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 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 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
Re: [Haskell-cafe] Mapping string to a function
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 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