Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.haskell > #167

So I want to be a haskell wizard

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!goblin2!goblin.stu.neva.ru!newsfeed1.swip.net!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!feed118.news.tele.dk!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail
From Turtle Wizard <0wl256NOSPAM@gmail.com>
Newsgroups comp.lang.haskell
Subject So I want to be a haskell wizard
Organization Faerun
Face iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAMFBMVEWXl5d7e3thYWH4+Pgf Hx+0tLSkpKSEhIRycnJOTk7///84ODjp6enZ2dnJyckICAhNWFMTAAAB2ElEQVQ4jY3TP0jj UBzA8YpUXQTP6dw0IFgObnELqdNbpIPBw7q08ZZ0O08FURdRkVMX/4DDFScp3vCjJyIdlIzl llLDgejUF1x6w9Fmuv35fm2Sl/QFzu+UvE/73q9tmgCvLwDPdR6AncX7hA/tWtmhPIB0MwJ2 1mx1rzQnAk9H3/Pdq5IWgcXz2XXcqqp27wMoElJkvHa1B1imguvMeOyF2XNW5PkjdOBnPywp PKqPWuwjpAMof4Kv+Ors0AfCjkFMpVXTWwjKRYVlttXpABoPi4cWjxDGJpar4gz6Z2+XEFwm xHUfBVyPTSmdWTP3CjgtAVdz4/u4Tm53TJgJwQ82eYJgTSQpXOcEXN7MZxAgVAB4eCzguLGA HzAW8LuKhUNeLGzw3g5QfsqyG9q0C7kolGx9g53SpvO5B1x9M/VvvO02B4ejUOhLWfc7BtXf r8uQSBiNwdS3mrTVg75cW7s4/SsdDi/J2pF11pLGhd9JNVW5y0UBz+G94/0fpr0koF4SuF4S LHhJUAgVAT953F9jc7iA2ykHZjsEWxUEfNfUiEEF2ENFBHxKdgfydQFpfRUBH7gVs6EK0JwF H8x88HNwKGl1fyujASHg+Yf7f/4OqB7guFTsBK8LQpBO0VdhGAAAAABJRU5ErkJggg==
X-Face iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAMFBMVEWXl5d7e3thYWH4+Pgf Hx+0tLSkpKSEhIRycnJOTk7///84ODjp6enZ2dnJyckICAhNWFMTAAAB2ElEQVQ4jY3TP0jj UBzA8YpUXQTP6dw0IFgObnELqdNbpIPBw7q08ZZ0O08FURdRkVMX/4DDFScp3vCjJyIdlIzl llLDgejUF1x6w9Fmuv35fm2Sl/QFzu+UvE/73q9tmgCvLwDPdR6AncX7hA/tWtmhPIB0MwJ2 1mx1rzQnAk9H3/Pdq5IWgcXz2XXcqqp27wMoElJkvHa1B1imguvMeOyF2XNW5PkjdOBnPywp PKqPWuwjpAMof4Kv+Ors0AfCjkFMpVXTWwjKRYVlttXpABoPi4cWjxDGJpar4gz6Z2+XEFwm xHUfBVyPTSmdWTP3CjgtAVdz4/u4Tm53TJgJwQ82eYJgTSQpXOcEXN7MZxAgVAB4eCzguLGA HzAW8LuKhUNeLGzw3g5QfsqyG9q0C7kolGx9g53SpvO5B1x9M/VvvO02B4ejUOhLWfc7BtXf r8uQSBiNwdS3mrTVg75cW7s4/SsdDi/J2pF11pLGhd9JNVW5y0UBz+G94/0fpr0koF4SuF4S LHhJUAgVAT953F9jc7iA2ykHZjsEWxUEfNfUiEEF2ENFBHxKdgfydQFpfRUBH7gVs6EK0JwF H8x88HNwKGl1fyujASHg+Yf7f/4OqB7guFTsBK8LQpBO0VdhGAAAAABJRU5ErkJggg==
Date Fri, 03 Feb 2012 19:42:34 +0900
Message-ID <sa6sjisdwpx.fsf@gmail.com> (permalink)
User-Agent Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.92 (gnu/linux)
Cancel-Lock sha1:RKhjDPTXXGZtp2QHs+waOZi61Zk=
MIME-Version 1.0
Content-Type text/plain
Lines 207
NNTP-Posting-Host 94.225.69.182
X-Trace news.sunsite.dk DXC=]C<j:Y<^Nm>jd^7_dR6Ih5YSB=nbEKnk;CcZFomX^oT2KPVSLA_UhI:X:m4R:`Xhk=CGLNFUj^I4>gdB@jc:J0Y7Ql:FViY53l0
X-Complaints-To staff@sunsite.dk
Xref x330-a1.tempe.blueboxinc.net comp.lang.haskell:167

Show key headers only | View raw


Hi,

I was wondering how one could write this scheme program in
a good haskell sense:

(define 'cons 0) ....

(define dispatch
        (vector cons
                un-cons
                car
                cdr
                set-car!
                set-cdr!
                pair?))

(lambda (<selector> . <arguments>)
(apply (vector-ref dispatch <selector>) <arguments>))))


After writing some 7 files of code (see below) I wondered if 
there are any better solutions:

-- code follows :

type ARGS = String 

readfunction :: [ARGS]->Int
readfunction s  = length s

writefunction :: [ARGS]->Int
writefunction s  = length s

type F = [ARGS]->Int
--type F = String->Int->[Char]
--type F = String->Int->[Int]

dispatchparser :: String -> [ARGS] -> F
dispatchparser msg args = case msg of
			"gnuvy" -> readfunction
			"foo" -> writefunction

main = do print "Foo" 
          print $ f([bar]) where
              bar = "foo"
              f = dispatchparser bar ["tully"]

-- code

type ARGS = String 

readfunction :: [ARGS]->Int
readfunction s  = length s

writefunction :: [ARGS]->Int
writefunction s  = length s

type F = [ARGS]->Int
--type F = String->Int->[Char]
--type F = String->Int->[Int]

dispatchparser :: String -> [ARGS] -> F
dispatchparser msg args = case msg of
			"gnuvy" -> readfunction
			"foo" -> writefunction

main = do print "Foo" 
          print $ f([bar]) where
              bar = "foo"
              f = dispatchparser bar ["tully"]

-- code

type ARGS = String 
--data ARGSDATA = Args String 
--		-- Args String 
--		-- String -- FIX
--		-- Int -- FIX
type ARGSLIST = [ARGS] 

readfunction :: ARGSLIST->Int
readfunction s  = length s

writefunction :: ARGSLIST->Int
writefunction s  = length s

type F = ARGSLIST->Int

dispatchparser :: String -> ARGSLIST -> F
dispatchparser msg args = case msg of
			"gnuvy" -> readfunction
			"foo" -> writefunction

main = do print "Foo" 
          print $ f([bar]) where
              bar = "foo"
              f = dispatchparser bar ["tully"]

-- code

type ARGS = String -- load at run-time 
--data ARGSDATA = ARGSDATA String 
--		-- Args String 
--		-- String -- FIX
--		-- Int -- FIX
type ARGSLIST = [ARGS] 

readfunction :: ARGSLIST->Int
readfunction s  = length s

writefunction :: ARGSLIST->Int
writefunction s  = length s

type F = ARGSLIST->Int

dispatchparser :: String -> ARGSLIST -> F
dispatchparser msg args = case msg of
			"gnuvy" -> readfunction
			"foo" -> writefunction

main = do print "Foo" 
          print $ f([bar]) where
              bar = "foo"
              f = dispatchparser bar ["tully"] -- ST-80 :-)


-- code

type ARGS = String -- load at run-time 
data ARGSDATA = ARGSDATA ARGS 
type ARGSLIST = [ARGSDATA] 

readfunction :: ARGSLIST->Int
readfunction s  = length s

writefunction :: ARGSLIST->Int
writefunction s  = length s

type F = ARGSLIST->Int

dispatchparser :: String -> ARGSLIST -> F
dispatchparser msg args = case msg of
			"gnuvy" -> readfunction
			"foo" -> writefunction

main = do print "Foo" 
          print $ f([argsdata2]) where
              bar = "foo"
              argsdata :: ARGSDATA
              argsdata = ARGSDATA "tully"
              argsdata2 :: ARGSDATA
              argsdata2 = ARGSDATA "tully2"
              f = dispatchparser bar [argsdata] -- ST-80 :-)

-- code


type ARGS = String -- load at run-time 
data ARGSDATA = ARGSDATA ARGS 
type ARGSLIST = [ARGSDATA] 

readfunction :: ARGSLIST->Int
readfunction s  = length s

writefunction :: ARGSLIST->Int
writefunction s  = length s

type F = ARGSLIST->Int

dispatchparser :: String -> ARGSLIST -> F
dispatchparser msg args = case msg of
			"gnuvy" -> readfunction
			"foo" -> writefunction

main = do print "Foo" 
          print $ f(argsdata2) where
              bar = "foo"
              argsdata :: ARGSLIST
              argsdata = [ARGSDATA "tully"]
              argsdata2 :: ARGSLIST
              argsdata2 = [ARGSDATA "tully2"]
              f = dispatchparser bar argsdata -- ST-80 :-)

-- code

readfunction :: Int->Int
readfunction i  = i
--equational readfunction = ReadFunction

writefunction :: Int->Int
writefunction i  = i
---equational writefunction = readfunction-- WriteFunction

--data F = Int

dispatchparser :: String -> (Int->Int) 
dispatchparser msg = case msg of
			"gnuvy" -> readfunction 
			"foo" -> writefunction 

main = do print "Foo" 
          print $ f(1) where
              f = dispatchparser "gnuvy"



TW

Back to comp.lang.haskell | Previous | NextNext in thread | Find similar | Unroll thread


Thread

So I want to be a haskell wizard Turtle Wizard <0wl256NOSPAM@gmail.com> - 2012-02-03 19:42 +0900
  Re: So I want to be a haskell wizard Paul Rubin <no.email@nospam.invalid> - 2012-02-03 16:09 -0800

csiph-web