challengeoreo.blogg.se

Cvs haskell
Cvs haskell










cvs haskell

Is much longer to type in every way than the equivalent (and probably faster) map snd.įurthermore when you're defining your own data structures often tuples are superfluous you could just write: data Command = Add User

Cvs haskell code#

There are a couple strange things in your code for example: lookupColumn :: -> lookup' can take in a list of any number of tuples, but must check if the column names match first.Īny help at all would be greatly appreciated. Unlike lookup', we know that the list this takes in has only the correct column's (Column, Integer) tuples within it. LookupColumn takes in a list of tuples and returns a list of the integers within it. ) <- a] returns a list of tuples that match only the first tuple in each list of (Column, Integer) tuples. Right now, it's only matching the first column, but I'd like it to work with any number of columns, not knowing which column the user wants ahead of time. select is the function which should return the list of integers in that column. Insert (Table "Revenue", ),Ī bit of explanation about the functions. Running: select example (User "Alice") (Table "Revenue") "Day" returns Just like it should, but replacing Day with Amount doesn't work. Right now, the format of the input has to be such that the column we want the values from must be the first column in the table. I have gotten it to work, but only in very select cases. Select a b c d = if not (elem (b, c) )Įlse Just (lookupColumn ) <- a]) Select :: -> User -> Table -> Column -> Maybe LookupColumn ((c, i):cvs) = if null cvs then else ++ lookupColumn cvs Lookup' c' ((c,i):cvs) = if c = c' then i else lookup' c' cvs Useful function for retrieving a value from a list module Database whereĭata User = User String deriving (Eq, Show)ĭata Table = Table String deriving (Eq, Show) somewhere in the list of commands there is one that matches "Allow (User name) (Table "Funds")". I'm trying to create a function that takes as parameters a list of commands, a User, a Table, a Column name (as a string), and returns a list containing the values in that column if the user has access to them (i.e. I've made a database of sorts, and the user can input commands like "Add (User "Name")" or "Create (Table "Funding")". Let it be known that I'm very new to Haskell and the declarative language part is totally different from what I'm used to.












Cvs haskell