Jump to content

Haskell (\\) Operator

- - - - -

  • Please log in to reply
4 replies to this topic

#1
nickknack

nickknack

    Newbie

  • Members
  • Pip
  • 1 posts
Hi guys,

I'm new to programming and just starting out in Haskell, and I came across \\ in some code. I've been unable to search for what it does because search engines do not recognise it as a word. Can someone help me out?

Thanks! :)

#2
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 853 posts
  • Location:Arkansas
In Haskell, the backslash ('\') character is used to represent lambda functions. A double backslash is an escaped backslash, i.e., a way of representing a literal backslash character.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.

– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#3
Tyapka

Tyapka

    Newbie

  • Members
  • Pip
  • 1 posts
Well I guess gregwarner's answer was not helpful. It was not for me anyway.

(\\) (double backslash) function in Haskell is a list difference function as found in Data.List module (Data/List.hs)

Implementation:

(\\) :: (Eq a) => [a] -> [a] -> [a]
(\\) = foldl (flip delete)

It accepts 2 lists and deletes the first occurrence of each element of the second list from the first list.

Examples:

(\\) [1,2,3] [2,3,4]
> [1]

(\\) [1,2,3,4,5] [2,3,4]
> [1,5]

(\\) [1,2,2] [2]
> [1,2] -- See how only one "2" is deleted from the original list.

#4
Sysop_fb

Sysop_fb

    Programmer

  • Members
  • PipPipPipPip
  • 160 posts
  • Location:Missouri
Hoogle

Hoogle for all your haskell function searching needs.
"The best optimizer is between your ears" - Michael Abrash
Saying you can optimize a program is like saying you understand how a program works on every level of every facet on a specific machines configuration.

#5
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 853 posts
  • Location:Arkansas
Thanks for the correction. Got mixed up there.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.

– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users