poole@CPSC-M-POOLE01 haskell % ghci GHCi, version 9.4.8: https://www.haskell.org/ghc/ :? for help ghci> :l Lists [1 of 1] Compiling Lists ( Lists.hs, interpreted ) Ok, one module loaded. ghci> :type numc numc :: Num a => (t -> Bool) -> [t] -> a ghci> :type flip flip :: (a -> b -> c) -> b -> a -> c ghci> hh x y z = 10000*x + 100*y + z ghci> flip hh 3 5 7 50307 ghci> [3..10] [3,4,5,6,7,8,9,10] ghci> [3,6..22] [3,6,9,12,15,18,21] ghci> take 10 [1..] [1,2,3,4,5,6,7,8,9,10] ghci> head [3..10] 3 ghci> tail [3..10] [4,5,6,7,8,9,10] ghci> [3..]!! 9 12 ghci> take 10 ([1..1000000000000]++[6]) [1,2,3,4,5,6,7,8,9,10] ghci> sum (take 10 ([1..1000000000000]++[6])) 55 ghci> myzip [1..] ['a'..'z'] :14:1: error: Variable not in scope: myzip :: [a0] -> [Char] -> t ghci> :l Lists2 [1 of 1] Compiling Lists2 ( Lists2.hs, interpreted ) Ok, one module loaded. ghci> myzip [1..] ['a'..'z'] [(1,'a'),(2,'b'),(3,'c'),(4,'d'),(5,'e'),(6,'f'),(7,'g'),(8,'h'),(9,'i'),(10,'j'),(11,'k'),(12,'l'),(13,'m'),(14,'n'),(15,'o'),(16,'p'),(17,'q'),(18,'r'),(19,'s'),(20,'t'),(21,'u'),(22,'v'),(23,'w'),(24,'x'),(25,'y'),(26,'z')] ghci> myzip [0..127] ['\0'..] [(0,'\NUL'),(1,'\SOH'),(2,'\STX'),(3,'\ETX'),(4,'\EOT'),(5,'\ENQ'),(6,'\ACK'),(7,'\a'),(8,'\b'),(9,'\t'),(10,'\n'),(11,'\v'),(12,'\f'),(13,'\r'),(14,'\SO'),(15,'\SI'),(16,'\DLE'),(17,'\DC1'),(18,'\DC2'),(19,'\DC3'),(20,'\DC4'),(21,'\NAK'),(22,'\SYN'),(23,'\ETB'),(24,'\CAN'),(25,'\EM'),(26,'\SUB'),(27,'\ESC'),(28,'\FS'),(29,'\GS'),(30,'\RS'),(31,'\US'),(32,' '),(33,'!'),(34,'"'),(35,'#'),(36,'$'),(37,'%'),(38,'&'),(39,'\''),(40,'('),(41,')'),(42,'*'),(43,'+'),(44,','),(45,'-'),(46,'.'),(47,'/'),(48,'0'),(49,'1'),(50,'2'),(51,'3'),(52,'4'),(53,'5'),(54,'6'),(55,'7'),(56,'8'),(57,'9'),(58,':'),(59,';'),(60,'<'),(61,'='),(62,'>'),(63,'?'),(64,'@'),(65,'A'),(66,'B'),(67,'C'),(68,'D'),(69,'E'),(70,'F'),(71,'G'),(72,'H'),(73,'I'),(74,'J'),(75,'K'),(76,'L'),(77,'M'),(78,'N'),(79,'O'),(80,'P'),(81,'Q'),(82,'R'),(83,'S'),(84,'T'),(85,'U'),(86,'V'),(87,'W'),(88,'X'),(89,'Y'),(90,'Z'),(91,'['),(92,'\\'),(93,']'),(94,'^'),(95,'_'),(96,'`'),(97,'a'),(98,'b'),(99,'c'),(100,'d'),(101,'e'),(102,'f'),(103,'g'),(104,'h'),(105,'i'),(106,'j'),(107,'k'),(108,'l'),(109,'m'),(110,'n'),(111,'o'),(112,'p'),(113,'q'),(114,'r'),(115,'s'),(116,'t'),(117,'u'),(118,'v'),(119,'w'),(120,'x'),(121,'y'),(122,'z'),(123,'{'),(124,'|'),(125,'}'),(126,'~'),(127,'\DEL')] ghci> (*5) 11 55 ghci> mymap (*5) [1..10] [5,10,15,20,25,30,35,40,45,50] ghci> mymap (mod 5) [1..20] [0,1,2,1,0,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5] ghci> (mod 5) 17 5 ghci> 17 mod 5 :22:1: error: • Could not deduce (Integral a0) from the context: (Integral a, Num t1, Num ((a -> a -> a) -> t1 -> t2)) bound by the inferred type for ‘it’: forall {a} {t1} {t2}. (Integral a, Num t1, Num ((a -> a -> a) -> t1 -> t2)) => t2 at :22:1-8 The type variable ‘a0’ is ambiguous Potentially matching instances: instance Integral Integer -- Defined in ‘GHC.Real’ instance Integral Int -- Defined in ‘GHC.Real’ ...plus one other ...plus one instance involving out-of-scope types (use -fprint-potential-instances to see them all) • In the ambiguity check for the inferred type for ‘it’ To defer the ambiguity check to use sites, enable AllowAmbiguousTypes When checking the inferred type it :: forall {a} {t1} {t2}. (Integral a, Num t1, Num ((a -> a -> a) -> t1 -> t2)) => t2 ghci> mod 5 17 5 ghci> (/ 5) 17 3.4 ghci> (/ 5) 17 3.4 ghci> (/ 5) [0..20] :26:2: error: • No instance for (Fractional [Integer]) arising from a use of ‘it’ • In the first argument of ‘print’, namely ‘it’ In a stmt of an interactive GHCi command: print it ghci> mymap (/ 5) [0..20] [0.0,0.2,0.4,0.6,0.8,1.0,1.2,1.4,1.6,1.8,2.0,2.2,2.4,2.6,2.8,3.0,3.2,3.4,3.6,3.8,4.0] ghci> mymap (5/) [0..20] [Infinity,5.0,2.5,1.6666666666666667,1.25,1.0,0.8333333333333334,0.7142857142857143,0.625,0.5555555555555556,0.5,0.45454545454545453,0.4166666666666667,0.38461538461538464,0.35714285714285715,0.3333333333333333,0.3125,0.29411764705882354,0.2777777777777778,0.2631578947368421,0.25] ghci> mymap (`mod` 5) [1..20] [1,2,3,4,0,1,2,3,4,0,1,2,3,4,0,1,2,3,4,0] ghci> mymap (5 `mod`) [1..20] [0,1,2,1,0,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5] ghci>