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: can run in ghci but can't compile. (Daniel Fischer)
2. Re: Logging in Haskell (Jason Dusek)
3. Re: Need help to edit the Haskell script in Winhugs and
documentation. (Jason Dusek)
4. Re: beginner's type error (Jason Dusek)
5. abou the Godel Numbering for untyped lambda calculus
(Algebras Math)
6. Re: [Haskell-cafe] abou the Godel Numbering for untyped
lambda calculus (Dan Weston)
7. Re: What is the Haskell idiom for "if then else if then"
(Paul Visschers)
8. Re: What is the Haskell idiom for "if then else if then"
(Hrushikesh Tilak)
9. making translation from imperative code (Michael Mossey)
----------------------------------------------------------------------
Message: 1
Date: Mon, 30 Mar 2009 20:13:24 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] can run in ghci but can't compile.
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-15"
Am Montag 30 März 2009 19:54:28 schrieb Anand Mitra:
> That does the job, Thanks !!
>
> Just to understand what is happening under the hood I tried to resolve this
> to the exact steps. The problem I faced seems to be equivalent of missing a
> -L and -l in gcc. Looking at the man for ghc I did find it had the -l and
> -L flags. Now I had to find the path and the name of the library. Did a
> find over the location I have installed ghc I was able to short list the
> likely candidates.
>
> ,----
>
> | find /opt/ghc-6.10.1/ -type f |grep \\.a$
> | ....
>
> /opt/ghc-6.10.1/lib/ghc-6.10.1/bytestring-0.9.1.4/libHSbytestring-0.9.1.4.a
>
> /opt/ghc-6.10.1/lib/ghc-6.10.1/bytestring-0.9.1.4/libHSbytestring-0.9.1.4_p
>.a
>
> | ....
>
> `----
>
> and as expected adding the -l and -L in the ghc command line does the
> trick.
>
> /opt/ghc-6.10.1/bin/ghc
> -L/opt/ghc-6.10.1/lib/ghc-6.10.1/bytestring-0.9.1.4/ -lHSbytestring-0.9.1.4
> cp.hs
>
> regards
Or, simpler:
ghc -package bytestring -o anfile anand.hs
but I strongly recommend using --make for every compilation unless you know
that you really do *not* want it.
------------------------------
Message: 2
Date: Mon, 30 Mar 2009 17:47:43 -0700
From: Jason Dusek <[email protected]>
Subject: Re: [Haskell-beginners] Logging in Haskell
To: Sergey Mikhanov <[email protected]>
Cc: "[email protected]" <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
In general, you can't do it -- there's no way to perform a
write to external logs in the midst of pure code. That would
mean it's not pure any more, consequently changing its type
signature and forcing you to rewrite a bunch of stuff. The
use of the GHCi debugger is highly recommended.
The first few times you use the debugger, you'll notice it
seems to go backward. That is laziness in action -- it goes
immediately to the result of an expression and then walks
backward as it is forced to evaluate the intermediate values.
Well, okay -- there is one way to do the logging like you
want; but it's dangerous. Use `unsafePerformIO` all over the
place and pray :)
--
Jason Dusek
|...GHCi debugger...|
http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-debugger.html
------------------------------
Message: 3
Date: Mon, 30 Mar 2009 18:01:56 -0700
From: Jason Dusek <[email protected]>
Subject: Re: [Haskell-beginners] Need help to edit the Haskell script
in Winhugs and documentation.
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
Wow, this made it on to GHC Trac:
http://hackage.haskell.org/trac/ghc/ticket/3127
--
Jason Dusek
------------------------------
Message: 4
Date: Mon, 30 Mar 2009 18:09:39 -0700
From: Jason Dusek <[email protected]>
Subject: Re: [Haskell-beginners] beginner's type error
To: Ivan Moore <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
2009/03/27 Ivan Moore <[email protected]>:
> > The reason (which is a bit confusing) is that it typechecks
> > just fine---if there *were* a type which is an instance of
> > both Integral and Floating (and I guess round needs RealFrac
> > as well), n could have that type. Â There isn't such a type
> > in the standard libraries, but in theory you could make up
> > your own type which is an instance of both.
>
> If there were such a type, could "10" have that type and then
> would my problem have not existed?
Yes, that is correct.
> in which case, why doesn't it!?
Does it actually make any logical sense for a type to be both
integral (governed by rules of modular division) and floating
point (governed by rules of IEEE 754 division)?
--
Jason Dusek
------------------------------
Message: 5
Date: Tue, 31 Mar 2009 02:55:25 +0100
From: Algebras Math <[email protected]>
Subject: [Haskell-beginners] abou the Godel Numbering for untyped
lambda calculus
To: beginners <[email protected]>, [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Hi all,
I am reading the book "The lambda calculus: Its syntax and Semantics" in the
chapter about Godel Numbering but I am confused in some points.
We know for Church Numerals, we have Cn = \fx.f^n(x) for some n>=0,
i.e. C0= \fx.x and C
1 = \fx.fx.
>From the above definition, I could guess the purpose of this kind of
encoding is trying to encode numeral via terms.
How about the Godel Numbering? From definition we know people say #M is the
godel number of M and we also have [M] = C#M to enjoy the second fixed point
theorem : for all F there exists X s.t. F[X] = X.
What the mapping function # is standing for? How could I use it? What the #M
will be? How to make use of the Godel Numbering?
Thank you very much!
alg
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20090331/fb94d606/attachment-0001.htm
------------------------------
Message: 6
Date: Mon, 30 Mar 2009 20:01:33 -0700
From: Dan Weston <[email protected]>
Subject: [Haskell-beginners] Re: [Haskell-cafe] abou the Godel
Numbering for untyped lambda calculus
To: Algebras Math <[email protected]>
Cc: beginners <[email protected]>, "[email protected]"
<[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="ISO-8859-1"; format=flowed
I can't tell exactly what you're asking, but I'll give it a try! :)
primes :: [Integer]
primes = [2,3,5,7,11,13,17,19,23,29,31,undefined]
godel :: String -> Integer
godel = product . zipWith (^) primes . map (toInteger . ord)
-- Here is the identity function (note that double backslash is a single
character
godel "\\x -> x"
1629920514342441477851613634029704631135430980107335428017064836156091059806450516131002598452000651374890570022191128551421788559667251656959733380229796871976693176094558797489489057311763922507760911447493016261397754567695234219623056037447490713525815311253273691703346455275115486717580778238094808661626709709766328915159206002675716287759792707200037683200000000000000000000000000000000
-- = 2^92 * 3^120 * 5^32 * 7^45 * 11^62 * 13^32 * 17^120
ungodel :: Integer -> String
-- ungodel . godel = id
(See http://en.wikipedia.org/wiki/Fundamental_theorem_of_arithmetic for
why this works).
These numbers get large quickly, but are finite for any finite string of
finite alphabet.
godel is a total function (every string has a unique integer), and its
inverse (an exercise to the reader involving prime factor decomposition)
would also be total if the alphabet were infinite (so that ord would be
total).
Frankly, I wouldn't know how to begin encoding the godel numbering in
the type system (shudder!), but being that it is a total primitive
recursive function, I suppose there is no theoretical impediment.
In contrast, Godel's Theorems themselves cannot be so encoded because
the last step involves a general recursive function.
Dan
Algebras Math wrote:
> Hi all,
>
> I am reading the book "The lambda calculus: Its syntax and Semantics" in
> the chapter about Godel Numbering but I am confused in some points.
>
> We know for Church Numerals, we have Cn = \fx.f^n(x) for some n>=0, i.e.
> C0 = \fx.x and C1 = \fx.fx.
>
> From the above definition, I could guess the purpose of this kind of
> encoding is trying to encode numeral via terms.
>
> How about the Godel Numbering? From definition we know people say #M is
> the godel number of M and we also have [M] = C#M to enjoy the second
> fixed point theorem : for all F there exists X s.t. F[X] = X.
>
> What the mapping function # is standing for? How could I use it? What
> the #M will be? How to make use of the Godel Numbering?
>
> Thank you very much!
>
> alg
>
------------------------------
Message: 7
Date: Tue, 31 Mar 2009 09:53:05 +0200
From: Paul Visschers <[email protected]>
Subject: Re: [Haskell-beginners] What is the Haskell idiom for "if
then else if then"
To: Peter Hickman <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
That works, but I guess a case statement would be nicer:
case compare r 0 of
LT -> LEFT
GT -> RIGHT
EQ -> STRAIGHT
This uses the compare function, which results in a value of the Ordering
datatype, which consists of the constructors LT, EQ and GT.
Peter Hickman wrote:
> I've just written this piece of code
>
> if r < 0
> then LEFT
> else
> if r > 0
> then RIGHT
> else STRAIGHT
>
> which works just fine but it does look rather clunky (as it would in any
> language I suppose). Is there a Haskell idiom for this type of code?
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Message: 8
Date: Tue, 31 Mar 2009 04:03:08 -0400
From: Hrushikesh Tilak <[email protected]>
Subject: Re: [Haskell-beginners] What is the Haskell idiom for "if
then else if then"
To: Peter Hickman <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
http://www.haskell.org/haskellwiki/If-then-else#Replace_syntactic_sugar_by_a_function
mentions that there is no such function in Prelude.
On Mon, Mar 30, 2009 at 11:33 AM, Peter Hickman <[email protected]> wrote:
>
> I've just written this piece of code
>
> if r < 0
> then LEFT
> else
> if r > 0
> then RIGHT
> else STRAIGHT
>
> which works just fine but it does look rather clunky (as it would in any
> language I suppose). Is there a Haskell idiom for this type of code?
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Message: 9
Date: Tue, 31 Mar 2009 05:54:12 -0700
From: Michael Mossey <[email protected]>
Subject: [Haskell-beginners] making translation from imperative code
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
I'm translating a Python program into Haskell, and running into a
problem---a type of code where I don't know how to make the conceptual
shift.
The Python code does a graphical layout of a music score. There is a
loop in which it add items (chords, symbols, text, etc.) one at a time,
moving to the right, until it reaches the end of the line. So in typical
imperative code, we have a bunch of loop state, such as
- xpos of last chord or symbol placed
- time of last chord or symbol placed
- several StaffData objects, each containing the symbols that went
on that particular staff
- a cache of miscellaneous information about each symbol for later
reference
So imperative code is pretty simple: loop, and each time update the
state. Much of this state consists of lists to which symbols are added
once per loop.
I'm not sure how to conceive of this problem in Haskell. Without using
mutable variables, I would have to "rebuild" the state on each loop. I
can do that, but I don't want to see an ugly proliferation of variables.
I would like to encapsulate the state in a single object so I can pass
it around as a single variable, like
LoopState = LoopState {
lastXPos :: Int,
lastTime :: Double,
staffDataLists :: [ ( String, StaffData ) ],
chunkCache :: [ ( Double, Chunk ) ]
}
So lets say I have an instance of this call x. Let's say I want to
create y, by "updating" lastXPos. Do I have to do something like this:
newLastXPos = 25
y = LoopState ( newLastXPos, lastTime x, staffDataLists x,
chunkCache x )
Obviously this is verbose compared to an imperative language in which
one would say:
newLastPos = 25
x.setLastXPos( newLastXPos )
I am aware that Haskell provides some mutable structures, but part of
what drew me to Haskell was the benefit of avoiding mutable data
(reducing bugs and making it easier to reason about my program's
behavior). Are there any shortcuts for doing things like the above?
Thanks,
Mike
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 9, Issue 43
****************************************