Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to [EMAIL PROTECTED]
You can reach the person managing the list at [EMAIL PROTECTED] When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Re: Type polymorphism with size (Michael Snoyman) 2. Re: Type polymorphism with size (Brent Yorgey) 3. Possible to update Haskell syntax (cm) 4. Trouble with formatting, Real World Haskell example (Robert Kosara) 5. Re: Trouble with formatting, Real World Haskell example (Ed McCaffrey) 6. Re: Trouble with formatting, Real World Haskell example (Ed McCaffrey) ---------------------------------------------------------------------- Message: 1 Date: Tue, 18 Nov 2008 21:37:16 -0800 From: "Michael Snoyman" <[EMAIL PROTECTED]> Subject: Re: [Haskell-beginners] Type polymorphism with size To: "Brent Yorgey" <[EMAIL PROTECTED]> Cc: beginners@haskell.org Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset="utf-8" On Tue, Nov 18, 2008 at 5:16 PM, Brent Yorgey <[EMAIL PROTECTED]>wrote: > > class RepTuple a b | a -> b where > > toList :: a -> [b] > > tMap :: (b -> b) -> a -> a > > > > instance RepTuple (a, a) a where > > toList (a, b) = [a, b] > > tMap f (a, b) = (f a, f b) > > > > And so on and so forth for every kind of tuple. Of course, this runs into > > the issue of the single case, for which I used the OneTuple library > > (actually, I wrote my own right now, but I intend to just use the > OneTuple > > library). > > > > This is reasonable too. It's just a tradeoff of hackishness vs. code > length/tediousness. I.e. in the solution with type-level naturals, you > don't need a separate instance like this for every number you're going > to use. And no one really likes writing things like > tMap f (a,b,c,d,e,g,h,i,j) = ... =) > > -Brent > I agree that it's not something people want to code; I was just thinking that a RepTuple kind of library might be useful for other purposes (ensuring lists of certain length essentially). Michael -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20081118/f8e54b53/attachment-0001.htm ------------------------------ Message: 2 Date: Wed, 19 Nov 2008 07:52:20 -0500 From: Brent Yorgey <[EMAIL PROTECTED]> Subject: Re: [Haskell-beginners] Type polymorphism with size To: beginners@haskell.org Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset=us-ascii On Tue, Nov 18, 2008 at 07:58:24PM -0800, David Frey wrote: > On 11/18/2008, "Michael Snoyman" <[EMAIL PROTECTED]> wrote: > > >I am trying to write some code to read flat files from a mainframe system. > >This includes some character fields. This is a fixed width file, so each > >field will have a consistent length between records, but there are fields of > >different length within a record. For example, I might have a "name" field > >length 20 and an eye color field length 5. > > > >I am trying to use the binary library to read in this file. I've written a > >binary type, MFChar2, for reading in a 2-length character field. It is > >defined as such (you can safely ignore the ebcdicToAscii piece, it is just > >doing character conversion): > > > >data MFChar2 = MFChar2 [Word8] > >instance Binary MFChar2 where > > put = undefined > > get = do ebcdic <- replicateM 2 getWord8 > > return $ MFChar2 $ map ebcdicToAscii ebcdic > > > >What I would like to do is have some kind of generic "MFChar" data type > >which could take any character length, but I can't figure out how to do it. > >Any help would be appreciated. > > > >Thanks, > >Michael > > > Is this something that could be accomplished using template Haskell? I > don't know anything about template Haskell, but maybe someone else on > the list can comment on this suggestion. Yes, in the sense that you could use Template Haskell to generate all the repetitive boilerplate code that you'd rather not write yourself, e.g. one instance of Binary for each number of Words. In this particular case it seems sort of overkill, in the sense that it probably wouldn't be worth the pain of learning how to use it. (For those who don't know, Template Haskell [1] is a GHC feature + library that lets you do compile-time metaprogramming/code generation.) -Brent [1] http://www.haskell.org/haskellwiki/Template_Haskell ------------------------------ Message: 3 Date: Sat, 22 Nov 2008 17:56:15 -0800 From: "cm" <[EMAIL PROTECTED]> Subject: [Haskell-beginners] Possible to update Haskell syntax To: <beginners@haskell.org> Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original I'm very interested in learning Haskell, but one frustration is that lists always require commas. As an example [1,2,3,4] is a valid expression, but [1 2 3 4] is not. In this ideal world, another example would be that [(fun1 3 4) 7] would be a valid expression and be a two-element list equivalent to [fun1 3 4, 7]. If what I am suggesting is syntactically possible and doesn't break more advanced features of the language that I (as a beginner) am unaware of, I'm interested in patching the open source for my own use (as well as others who might want it). ------------------------------ Message: 4 Date: Sat, 22 Nov 2008 21:53:37 -0500 From: "Robert Kosara" <[EMAIL PROTECTED]> Subject: [Haskell-beginners] Trouble with formatting, Real World Haskell example To: beginners@haskell.org Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset="iso-8859-1" I'm having some trouble getting the InteractWith example from Real World Haskell's Chapter 4 to compile. When I use spaces (like below), it says "Interact.hs:10:30: Empty 'do' construct." When I use tabs (4 spaces per tab), I get "Interact.hs:16:13: parse error on input `='." In either case, I don't see the problem. Any help would be greatly appreciated. I'm also confused about the formatting of the example in the book (page 72). The last line ("myFunction = id") seems to be indented between the where and the next line, why is that? Is that simply a layout problem? To me, it seems it should be on the same level as the where. Below is my program: -- Interact.hs, simple filter in Haskell import System.Environment (getArgs) interactWith function inputFile outputFile = do input <- readFile inputFile writeFile outputFile (function input) main = mainWith myFunction where mainWith function = do args <- getArgs case args of [input, output] -> interactWith function input output _ -> putStrLn "Usage: Interact inputFile outputFile" myFunction = id Regards, Robert -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20081122/e2f2318b/attachment-0001.htm ------------------------------ Message: 5 Date: Sat, 22 Nov 2008 22:41:29 -0500 From: "Ed McCaffrey" <[EMAIL PROTECTED]> Subject: Re: [Haskell-beginners] Trouble with formatting, Real World Haskell example To: beginners@haskell.org Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset="iso-8859-1" On Sat, Nov 22, 2008 at 9:53 PM, Robert Kosara <[EMAIL PROTECTED]> wrote: > I'm having some trouble getting the InteractWith example from Real World > Haskell's Chapter 4 to compile. When I use spaces (like below), it says > "Interact.hs:10:30: Empty 'do' construct." When I use tabs (4 spaces per > tab), I get "Interact.hs:16:13: parse error on input `='." In either case, I > don't see the problem. Any help would be greatly appreciated. > I'm also confused about the formatting of the example in the book (page > 72). The last line ("myFunction = id") seems to be indented between the > where and the next line, why is that? Is that simply a layout problem? To > me, it seems it should be on the same level as the where. > > Below is my program: > > -- Interact.hs, simple filter in Haskell > > import System.Environment (getArgs) > > interactWith function inputFile outputFile = do > input <- readFile inputFile > writeFile outputFile (function input) > > main = mainWith myFunction > where mainWith function = do > args <- getArgs > case args of > [input, output] -> interactWith function input output > _ -> putStrLn "Usage: Interact inputFile outputFile" > > myFunction = id > > > Regards, > > Robert > > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20081122/e37ea330/attachment-0001.htm ------------------------------ Message: 6 Date: Sat, 22 Nov 2008 22:41:47 -0500 From: "Ed McCaffrey" <[EMAIL PROTECTED]> Subject: Re: [Haskell-beginners] Trouble with formatting, Real World Haskell example To: beginners@haskell.org Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset="iso-8859-1" I hope the spacing is preserved by my email client; here's a formatting that compiles: import System.Environment (getArgs) interactWith function inputFile outputFile = do input <- readFile inputFile writeFile outputFile (function input) main = mainWith myFunction where mainWith function = do args <- getArgs case args of [input, output] -> interactWith function input output _ -> putStrLn "Usage: Interact inputFile outputFile" myFunction = id On Sat, Nov 22, 2008 at 9:53 PM, Robert Kosara <[EMAIL PROTECTED]> wrote: > I'm having some trouble getting the InteractWith example from Real World > Haskell's Chapter 4 to compile. When I use spaces (like below), it says > "Interact.hs:10:30: Empty 'do' construct." When I use tabs (4 spaces per > tab), I get "Interact.hs:16:13: parse error on input `='." In either case, I > don't see the problem. Any help would be greatly appreciated. > I'm also confused about the formatting of the example in the book (page > 72). The last line ("myFunction = id") seems to be indented between the > where and the next line, why is that? Is that simply a layout problem? To > me, it seems it should be on the same level as the where. > > Below is my program: > > -- Interact.hs, simple filter in Haskell > > import System.Environment (getArgs) > > interactWith function inputFile outputFile = do > input <- readFile inputFile > writeFile outputFile (function input) > > main = mainWith myFunction > where mainWith function = do > args <- getArgs > case args of > [input, output] -> interactWith function input output > _ -> putStrLn "Usage: Interact inputFile outputFile" > > myFunction = id > > > Regards, > > Robert > > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > On Sat, Nov 22, 2008 at 10:41 PM, Ed McCaffrey <[EMAIL PROTECTED]> wrote: > > > On Sat, Nov 22, 2008 at 9:53 PM, Robert Kosara <[EMAIL PROTECTED]> wrote: > >> I'm having some trouble getting the InteractWith example from Real World >> Haskell's Chapter 4 to compile. When I use spaces (like below), it says >> "Interact.hs:10:30: Empty 'do' construct." When I use tabs (4 spaces per >> tab), I get "Interact.hs:16:13: parse error on input `='." In either case, I >> don't see the problem. Any help would be greatly appreciated. >> I'm also confused about the formatting of the example in the book (page >> 72). The last line ("myFunction = id") seems to be indented between the >> where and the next line, why is that? Is that simply a layout problem? To >> me, it seems it should be on the same level as the where. >> >> Below is my program: >> >> -- Interact.hs, simple filter in Haskell >> >> import System.Environment (getArgs) >> >> interactWith function inputFile outputFile = do >> input <- readFile inputFile >> writeFile outputFile (function input) >> >> main = mainWith myFunction >> where mainWith function = do >> args <- getArgs >> case args of >> [input, output] -> interactWith function input output >> _ -> putStrLn "Usage: Interact inputFile outputFile" >> >> myFunction = id >> >> >> Regards, >> >> Robert >> >> >> _______________________________________________ >> Beginners mailing list >> Beginners@haskell.org >> http://www.haskell.org/mailman/listinfo/beginners >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20081122/8fa7b437/attachment.htm ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 5, Issue 12 ****************************************