Personal tools

Talk:Hitchhikers guide to Haskell

From HaskellWiki

Revision as of 23:21, 30 July 2011 by Mgm7734 (Talk | contribs)

Jump to: navigation, search


1 Code Indentation:

Haskell code should be indented using the <haskell> tag:

This also allows for proper cut and paste properties.

P.S. I am really enjoying this article! It provides a very nice practical introduction to Haskell. Thanks! Mforbes 10:08, 17 April 2006 (UTC)

2 Problems

When I try to compile, or load into ghci, the following code I get get this error:

   No instance for (Text.Parsec.Prim.Stream s m Char)
     arising from a use of `many' at cd-fit.hs:8:13-27
   Possible fix:
     add an instance declaration for (Text.Parsec.Prim.Stream s m Char)
   In a stmt of a 'do' expression: dirs <- many dirAndSize
   In the expression:
       do dirs <- many dirAndSize
          return dirs
   In the definition of `parseInput':
       parseInput = do dirs <- many dirAndSize
                       return dirs
   Failed, modules loaded: none.

And I panic.


module Main where
import Text.ParserCombinators.Parsec
data Dir = Dir Int String deriving Show
parseInput = 
  do dirs <- many dirAndSize
     return dirs
dirAndSize = 
  do size <- many1 digit
     dir_name <- anyChar `manyTill` newline
     return (Dir (read size) dir_name)
main = do input <- getContents
          putStrLn $ "DEBUG: got input " ++ input
          -- compute solution and print it


3 Solution

I solved the above problem by adding a signature to one function:

parseInput :: Parser [Dir]       
parseInput = ...

4 Knapsack problem?

Surely this is actually an example of bin packing? No?