SHARE
TWEET

Untitled

a guest Jun 19th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Data.List (lookup)
  2.  
  3. insert :: Eq a => (a,b) -> [(a,b)] -> [(a,b)]
  4. insert (a,b)  []           = [(a,b)]
  5. insert (a,b) ((c,d):rest) = if a == c
  6.     then (a,b) : rest
  7.     else (c,d) : insert (a,b) rest
  8.  
  9. dict :: [(String, String)]
  10. dict = [("", "")]
  11.  
  12. main = do
  13.     insert ("onekey", "onevalue") dict
  14.     print dict
  15.     print $ lookup "onekey" dict
  16.      
  17. $ runghc rndict.hs
  18.  
  19. rndict.hs:22:1: error:
  20.     • Couldn't match expected type ‘IO t0’ with actual type ‘[()]’
  21.     • In the expression: main
  22.       When checking the type of the IO action ‘main’
  23.  
  24. rndict.hs:24:9: error:
  25.     • Couldn't match type ‘IO’ with ‘[]’
  26.       Expected type: [()]
  27.         Actual type: IO ()
  28.     • In a stmt of a 'do' block: print dict
  29.       In the expression:
  30.         do { insert ("onekey", "onevalue") dict;
  31.              print dict;
  32.              print $ lookup "onekey" dict }
  33.       In an equation for ‘main’:
  34.           main
  35.             = do { insert ("onekey", "onevalue") dict;
  36.                    print dict;
  37.                    print $ lookup "onekey" dict }
  38.  
  39. rndict.hs:25:9: error:
  40.     • Couldn't match type ‘IO’ with ‘[]’
  41.       Expected type: [()]
  42.         Actual type: IO ()
  43.     • In a stmt of a 'do' block: print $ lookup "onekey" dict
  44.       In the expression:
  45.         do { insert ("onekey", "onevalue") dict;
  46.              print dict;
  47.              print $ lookup "onekey" dict }
  48.       In an equation for ‘main’:
  49.           main
  50.             = do { insert ("onekey", "onevalue") dict;
  51.                    print dict;
  52.                    print $ lookup "onekey" dict }
  53.      
  54. import Data.List (lookup)
  55.  
  56. insert :: Eq a => (a,b) -> [(a,b)] -> [(a,b)]
  57. insert (a,b)  []           = [(a,b)]
  58. insert (a,b) ((c,d):rest) = if a == c
  59.     then (a,b) : rest
  60.     else (c,d) : insert (a,b) rest
  61.  
  62. dict :: [(String, String)]
  63. dict = [("", "")]
  64.  
  65. main = do
  66.     let d = insert ("onekey", "onevalue") dict
  67.     print d
  68.     print $ lookup "onekey" d
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top