Application of lookup function

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

Application of lookup function

Jeon-Young Kang
Hi all.

I'd like to apply lookup function (Data.Map) for what I am working on.

Here is my code.

data Person = Person {personId :: Int, name = String}
data People = [Person]

data State = InMembership | NoMemebership

person1 = Person {1 = personId, "James" = name}
person2 = Person {2 = personId, "Tom" = name}

members = People [person1, person2]

class Belonging a where
      belonging :: a -> [a] -> Bool -> State

here is the problem...
I don't know how to get to know whether a person is belong to members.
I'd like to find it through a person's name.

Can you suggest any examples??

Sincerely,
Jeon 
 
   

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

Re: Application of lookup function

Alex Belanger

The (`elem` members) function will tell you if the person is a member of members. You can then turn that boolean into your custom State type.

On Dec 3, 2015 11:46 PM, "Jeon-Young Kang" <[hidden email]> wrote:
Hi all.

I'd like to apply lookup function (Data.Map) for what I am working on.

Here is my code.

data Person = Person {personId :: Int, name = String}
data People = [Person]

data State = InMembership | NoMemebership

person1 = Person {1 = personId, "James" = name}
person2 = Person {2 = personId, "Tom" = name}

members = People [person1, person2]

class Belonging a where
      belonging :: a -> [a] -> Bool -> State

here is the problem...
I don't know how to get to know whether a person is belong to members.
I'd like to find it through a person's name.

Can you suggest any examples??

Sincerely,
Jeon 
 
   

_______________________________________________
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: Application of lookup function

Jeon-Young Kang
Thanks Alex.

I successfully implemented what I want by using 'elem'. 

On Thu, Dec 3, 2015 at 11:50 PM, Alex Belanger <[hidden email]> wrote:

The (`elem` members) function will tell you if the person is a member of members. You can then turn that boolean into your custom State type.

On Dec 3, 2015 11:46 PM, "Jeon-Young Kang" <[hidden email]> wrote:
Hi all.

I'd like to apply lookup function (Data.Map) for what I am working on.

Here is my code.

data Person = Person {personId :: Int, name = String}
data People = [Person]

data State = InMembership | NoMemebership

person1 = Person {1 = personId, "James" = name}
person2 = Person {2 = personId, "Tom" = name}

members = People [person1, person2]

class Belonging a where
      belonging :: a -> [a] -> Bool -> State

here is the problem...
I don't know how to get to know whether a person is belong to members.
I'd like to find it through a person's name.

Can you suggest any examples??

Sincerely,
Jeon 
 
   

_______________________________________________
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




--
Department of Geography
State University of New York at Buffalo

 
Jeon-Young Kang

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