can this be made shorter?

hi, i want to know if a string contains only "." and "/" characters. i do something like that: null . dropWhile (\c -> c == '.' || c == '/') now it's a shame, because if I wanted only to check for "." then I would have: null . dropWhile (=='.') afaik in scala you can say: null . dropWhile (_ == '.' || _ == '/') which is a bit more compact than the haskell... I was thinking to use "and" but I'm not sure it would end up being readable... Any idea? Or I am trying too hard to make it compact? Emmanuel

Well, you could use:
null . dropWhile (`elem` "./")
=)
On Wed, May 29, 2013 at 4:38 PM, Emmanuel Touzery
hi,
i want to know if a string contains only "." and "/" characters.
i do something like that:
null . dropWhile (\c -> c == '.' || c == '/')
now it's a shame, because if I wanted only to check for "." then I would have:
null . dropWhile (=='.')
afaik in scala you can say:
null . dropWhile (_ == '.' || _ == '/')
which is a bit more compact than the haskell...
I was thinking to use "and" but I'm not sure it would end up being readable...
Any idea? Or I am trying too hard to make it compact?
Emmanuel
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
-- Felipe.

Thank you, that's exactly what I was looking for! I didn't spot "elem" so far... that's why I was looking into "and" which was too complex for this case. Thanks again! emmanuel On Wed, May 29, 2013 at 9:44 PM, Felipe Almeida Lessa < felipe.lessa@gmail.com> wrote:
Well, you could use:
null . dropWhile (`elem` "./")
=)
On Wed, May 29, 2013 at 4:38 PM, Emmanuel Touzery
wrote: hi,
i want to know if a string contains only "." and "/" characters.
i do something like that:
null . dropWhile (\c -> c == '.' || c == '/')
now it's a shame, because if I wanted only to check for "." then I would have:
null . dropWhile (=='.')
afaik in scala you can say:
null . dropWhile (_ == '.' || _ == '/')
which is a bit more compact than the haskell...
I was thinking to use "and" but I'm not sure it would end up being readable...
Any idea? Or I am trying too hard to make it compact?
Emmanuel
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
-- Felipe.
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

ah, i wrote "and" but i meant "all" in my emails ;-)
but yes i thought about all in combination with the null, to go over "."
and "/".
yes this is clearer, just too bad about the flip.
On Wed, May 29, 2013 at 10:00 PM, Tilmann
you might want to use 'all' as well:
Prelude> (all $ flip elem "./") "...." True
Am 29.05.2013 21:50, schrieb Emmanuel Touzery:
null . dropWhile (`elem` "./")
______________________________**_________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/**mailman/listinfo/beginnershttp://www.haskell.org/mailman/listinfo/beginners

On Wed, 29 May 2013 22:00:58 +0200, Tilmann
you might want to use 'all' as well:
Prelude> (all $ flip elem "./") "...." True
or: all (`elem` "./") "...." Regards, Henk-Jan van Tuyl -- Folding@home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming --

afaik in scala you can say:
null . dropWhile (_ == '.' || _ == '/')
which is a bit more compact than the haskell...
No, it would be desugared to: dropWhile ((a,b) => a == '.' || b == '/') scala> "abc".dropWhile(_ == '.' || _ == '/') <console>:8: error: wrong number of parameters; expected = 1 "abc".dropWhile(_ == '.' || _ == '/') You would have to do the same thing as in Haskell to make it work: scala> "abc".dropWhile(a => a == '.' || a == '/') res20: String = abc Cheers Sylvain
participants (5)
-
Emmanuel Touzery
-
Felipe Almeida Lessa
-
Henk-Jan van Tuyl
-
Sylvain HENRY
-
Tilmann