Make function shorter in Haskell -


is possible away variable x in function?:

numocc x = map (length.filter(==x)) 

for example if have function:

numocc x l = map (countt x) l 

i can away variable l , this:

numocc x = map (countt x) 

thanks help.

you can use "pointfree" program answer questions this

> pointfree "numocc x = map (length . filter (==x))"  numocc = map . (length .) . filter . (==) 

edit

here in action

> let numocc x = map (length . filter (==x)) > let numocc' = map . (length .) . filter . (==)  numocc 'a' ["aa", "bb"] --outputs [2, 0] numocc' 'a' ["aa", "bb"] --also outputs [2, 0] 

basically, counts number of param1's in each element in list items of param2

numocc 'a' ["aa", "bba"] --outputs [2, 1] numocc' 'a' ["aa", "bba"] --also outputs [2, 1] 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -