Send Beginners mailing list submissions to
[email protected]
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: Turing machine that decides if a string is an element of
an-bn-cn (Nick Vanderweit)
2. Re: Control.Exception.bracket-like for MonadIO ? (Olivier Iffrig)
3. monads do not fit together? (Kees Bleijenberg)
----------------------------------------------------------------------
Message: 1
Date: Sun, 13 Oct 2013 13:37:55 -0600
From: Nick Vanderweit <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Turing machine that decides if a
string is an element of an-bn-cn
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Hi Roger,
This is an interesting way to represent the machine. At first, I didn't
see why the states had types like:
state1 :: String -> Char -> String -> Bool
But now I see that, in:
state1 x h y = ...
x is the portion of the tape left of the head, h is the character under
the head, and y is the portion of the tape to the right. One idea would
be to represent the left part of the tape backwards. That is, if the
tape looks like:
[..., 0, 1, 2, 3, 4, ...]
^
Instead of representing the tape state as the tuple ([..., 0, 1], 2, [3,
4, ...]), use ([1, 0, ...], 2, [3, 4, ...]). This will let you avoid
walking the entire left part of the tape to match patterns like:
(x++"X")
For instance, your state3 would look like:
state3 x h y = state4 ('X':x) (head y) (tail y)
It's neat that you represent state transitions as tail calls to other
states. I wrote a Turing Machine representation recently [1] which I
believe is a bit more traditional. It allows you to parameterize the
machine over any type of symbols or states, and gives a general way to
represent tapes. There, the transitions are represented by a function of
type:
state -> sym -> Maybe (state, sym, Shift)
Nick
[1] https://gist.github.com/nvanderw/6821856
On 10/12/2013 01:55 PM, Costello, Roger L. wrote:
> Hi Folks,
>
> I implemented, in Haskell, a Turing Machine that decides if a string is a
> member of the language consisting of an equal number of a's, b's, and c's,
> i.e., anbncn.
>
> http://www.xfront.com/Turing-Machines/an-bn-cn/TM.hs.txt
>
> /Roger
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 295 bytes
Desc: OpenPGP digital signature
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20131013/ba68b297/attachment-0001.sig>
------------------------------
Message: 2
Date: Mon, 14 Oct 2013 10:32:20 +0200
From: Olivier Iffrig <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Control.Exception.bracket-like for
MonadIO ?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
Michael Snoyman wrote (2013-10-10 11:03:06 +0200):
> I'd recommend checking out Control.Exception.Lifted from lifted-base:
>
> http://haddocks.fpcomplete.com/fp/7.4.2/20130922-179/lifted-base/Control-Exception-Lifted.html
Thanks, that seems to be what I was looking for. I didn't know about
this package, and did not have the time to test yet, but I guess it will
fit perfectly.
--
Olivier
------------------------------
Message: 3
Date: Mon, 14 Oct 2013 13:51:30 +0200
From: "Kees Bleijenberg" <[email protected]>
To: <[email protected]>
Subject: [Haskell-beginners] monads do not fit together?
Message-ID: <000f01cec8d3$b8cb29e0$2a617da0$@[email protected]>
Content-Type: text/plain; charset="us-ascii"
The program belows reads the get fields 'un' and 'ip'. If these get fields
both exist, the program modifies a firewall script.
The problem is in cgiMain.
The error at the problem line is: parse error on input `<-'
If I move the line above the 'if' I get: Couldn't match expected type `CGIT
IO t0' with actual type `IO [String]'.
How can I extract values from the IO [String] monad in cgiMain? I don't want
to alter the type of runRefreshFirewall.
Kees
module Main(
main
)
where
import Network.CGI
import Text.XHtml
import Text.XHtml.Transitional
import Data.Maybe
runRefreshFirewall :: String -> String -> IO [String]
runRefreshFirewall un ip = do
return ["test" ]
inputCgiOkPage :: String -> String -> [String] -> Html
inputCgiOkPage un ip msgs = body << h1 << ("IP: " ++ (show ip))
undefinedFieldsPage :: Html
undefinedFieldsPage = body << h1 << "Undefined Fields"
cgiMain :: CGI CGIResult
cgiMain = do
maybeUn <- getInput "un"
maybeIp <- getInput "ip"
if ((isJust maybeUn) && (isJust maybeIp)) then
msgs <-runRefreshFirewall (fromJust maybeUn) (fromJust
maybeIp) -- problem
output $ renderHtml $ inputCgiOkPage (fromJust maybeUn)
(fromJust maybeIp) msgs
else
output $ renderHtml undefinedFieldsPage
main :: IO ()
main = runCGI $ handleErrors cgiMain
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20131014/3598883f/attachment-0001.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 64, Issue 22
*****************************************