Compare string contents in haskell

I have 2 line lists for example:

listx = ["name","age","rank"]
input = ["name","age"]

How to compare two lists to check if listx "name"and "age"in input?

+3
source share
4 answers

Is this homework? :)

You need to create one or two recursive functions to go through both lists and search for each line in the input.

Or you could find some good features in Prelude that help here.

+4
source

B is a subset of A if B \ A is empty

so another way to do this is

import Data.List ((\\))
null (input \\ listx)
+6
source
all (flip elem listx) input

. , , ...

+5

.

import Data.Set
(fromList input) `isSubsetOf` (fromList listX)
+4

Source: https://habr.com/ru/post/1708114/


All Articles