Making a set data type with list data structure in Haskell -


write insert , member operations in haskell. make sure in ml , haskell set data type distinct list. in haskell, define set type instance of classes eq , show.

let setadd l n = if (elem l n) l else l ++ [n] let setmember l = l !! 

the code written above makes have functions perform on lists.

is there way make class? sorry, i'm learning functional programming. there way make set class has member variables such list?

your data type here [a], has such instances available, including eq , show (that way right thing).

if want have write own instances, should newtype underlying type, in fashion similar to:

newtype set = set { getset :: [a] } 

then can write:

instance show => show (set a)     show (set a) = ...  instance eq => eq (set a)     set == set b = ... 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -