searching for an element from a list of tuples

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

searching for an element from a list of tuples

Anvika Kumar
I have a tuple with three values and i want to remove the tuple which contains a particular name. 

So d = (name, month, date)
 i take a user input of name and then search the list which has tuples of the above declared type. Which ever tuple has the name it should be deleted from the list.
 
d is the tuple.
db should be a list of tuples.


remove :: (Eq) =>  IO String  -> d
print "Enter the name to be removed”
a <- getLine
      remove x [] = []
      print “Record not found”
      remove x db = 
         if x == 



Please let me know!

Thanks a lot


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: searching for an element from a list of tuples

Sumit Sahrawat, Maths & Computing,
 IIT (BHU)

Try pattern matching on the list head and tail as in (x:xs). Take a look at the source code for filter [1], which can be put to use here.

[1]: http://hackage.haskell.org/package/base-4.8.2.0/docs/src/GHC.List.html#filter

Regards,
  Sumit

On 09-May-2016 9:41 am, "Anvika Kumar" <[hidden email]> wrote:
I have a tuple with three values and i want to remove the tuple which contains a particular name. 

So d = (name, month, date)
 i take a user input of name and then search the list which has tuples of the above declared type. Which ever tuple has the name it should be deleted from the list.
 
d is the tuple.
db should be a list of tuples.


remove :: (Eq) =>  IO String  -> d
print "Enter the name to be removed”
a <- getLine
      remove x [] = []
      print “Record not found”
      remove x db = 
         if x == 



Please let me know!

Thanks a lot


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: searching for an element from a list of tuples

Anvika Kumar
Let me review and get back. Thank you.

Anvika
Graduate Student 
STONY BROOK UNIVERSITY

On Mon, May 9, 2016 at 6:25 PM, Sumit Sahrawat, Maths & Computing, IIT (BHU) <[hidden email]> wrote:

Try pattern matching on the list head and tail as in (x:xs). Take a look at the source code for filter [1], which can be put to use here.

[1]: http://hackage.haskell.org/package/base-4.8.2.0/docs/src/GHC.List.html#filter

Regards,
  Sumit

On 09-May-2016 9:41 am, "Anvika Kumar" <[hidden email]> wrote:
I have a tuple with three values and i want to remove the tuple which contains a particular name. 

So d = (name, month, date)
 i take a user input of name and then search the list which has tuples of the above declared type. Which ever tuple has the name it should be deleted from the list.
 
d is the tuple.
db should be a list of tuples.


remove :: (Eq) =>  IO String  -> d
print "Enter the name to be removed”
a <- getLine
      remove x [] = []
      print “Record not found”
      remove x db = 
         if x == 



Please let me know!

Thanks a lot


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners



_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners