Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.haskell > #167
| From | Turtle Wizard <0wl256NOSPAM@gmail.com> |
|---|---|
| Newsgroups | comp.lang.haskell |
| Subject | So I want to be a haskell wizard |
| Organization | Faerun |
| Date | 2012-02-03 19:42 +0900 |
| Message-ID | <sa6sjisdwpx.fsf@gmail.com> (permalink) |
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 | Next — Next in thread | Find similar | Unroll 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