Haskell / GHC: using field names 
Author Message
 Haskell / GHC: using field names

Hi!

I really can't figure out how to use named (or 'labeled') fields with
haskell. According to

http://www.*-*-*.com/ #records

the following (massively cut-down from a mp3 "jukebox" server app I'm
trying to write) should be correct (if I got it right :-) ):

import IO

type Song = String
data PlayState = Playing Handle | Paused deriving Show

data State = State {
    playList :: [Song],
    playState :: PlayState

Quote:
} deriving Show

main :: IO ()
main = do
    let pl = ["test.mp3", "test2.mp3"]
    current <- openFile (head pl) ReadMode
    let st = st {
       playList  = pl,
       playState = (Playing current)
    }
    putStrLn (show (playList st))

Well, at least ghc doesn't complain when it's compiled. But if I try to
execute the binary I just get:

Fail: <<loop>>

as a result of the putStrLn on the last line. The same with ghci. So ghc
has detected an endless loop. But why? Can s.o. explain to me what I'm
doing wrong?

Thanks in advance,
Matthias Treydte

PS: I'm using ghc-6.0



Sat, 03 Dec 2005 20:06:50 GMT  
 Haskell / GHC: using field names
On Tue, 17 Jun 2003 14:06:50 +0200,

Quote:

>    let st = st {

You use "st" recursivly here, you do probably mean:

let st = State {

/Hampus

--
"Man skall inte gl?djas i on?dan."



Sat, 03 Dec 2005 20:21:08 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Haskell (GHC) - Help managing memory

2. Calling Haskell function from C (FFI) causes seg-fault (GHC,linux)

3. Haskell optimizations in GHC

4. GHC confusion, and a few haskell questions.

5. Concurrent Haskell (GHC) and Win32 Applications ?

6. Problem with GHC Haskell install and default libs

7. Hugs 1.4, Haskell: the Craft of Functional Programming, and GHC

8. Haskell compiler ghc - slow?

9. Using a string to determine a field name

10. Name “FIELD” is already used by another control or column

11. Field names in a field...

12. Selecting Fields Based On Field Name

 

 
Powered by phpBB® Forum Software