Segfault
Michal Safranek
wejn@box.cz
Tue, 4 Jun 2002 21:03:49 +0200
{-
Story:
I had 'Functional programming' exam today ... (which I totally screwed up)
After returning to campus I tried to verify some of my results in hugs-Dec2001
The goal was implementing 'cons' parser to parse either '[1,2,3,...]'
or '1:2:3:...:[...]'
My example didn't worked (what a surprise :( ). I tried to play with hugs ...
and made little mistake in my code ...
instead of 'cons = numbers >>= (\x -> enumlist >>= (\y -> return (x ++ y)))'
I wrote: 'cons = numbers >>= (\x -> listterm >>= (\y -> return (x ++ y)))'
... complete program and result can be found below ...
(I'm sending this here because it seems strange getting segfault to me ...)
Sincerely,
Wejn
PS: Please keep in mind this code was written by total beginner (=me) ...
--
Michal Safranek <wejn(at)svamberk.net>
(svamberk.net's Linux section, fi.muni.cz student, linuxfan)
>>> Bored? Want hours of entertainment? <<<
>>> Just set the initdefault to 6! <<<
-}
import ParseLib
listterm :: Parser [Int]
listterm = cons `chainr1` ops [(symbol "++", (++))]
enumlist :: Parser [Int]
enumlist = bracket (symbol "[") (sepby int (symbol ",")) (symbol "]")
cons :: Parser [Int]
-- cons = ...??...
numbers :: Parser [Int]
numbers = sepby int (symbol ":")
cons = numbers >>= (\x -> listterm >>= (\y -> return (x ++ y)))
{-
-- it really should be:
cons = enumlist +++ (numbers >>= (\x -> symbol ":" >> listterm >>=
(\y -> return (x ++ y))))
-- (just in case you're interested)
-}
{-
Hugs session for:
/usr/local/share/hugs/lib/Prelude.hs
/usr/local/share/hugs/lib/Char.hs
/usr/local/share/hugs/lib/Monad.hs
/usr/local/share/hugs/lib/hugs/ParseLib.hs
a.hs
Type :? for help
Main> papply listterm "1:2:3:[]"
Segmentation fault
-}