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: cmath Install troubles (Tom Murphy)
2. Re: Cross-platform .hs files on Linux and Windows
(Daniel Fischer)
3. Re: Cross-platform .hs files on Linux and Windows (Vinay
Sajip)
4. Re: Program reliability and multiple data constructors;
polymorphism (Tim Perry)
5. Re: Training tasks (Nikita Beloglazov)
6. Re: Cross-platform .hs files on Linux and Windows
(Brandon Allbery)
----------------------------------------------------------------------
Message: 1
Date: Thu, 19 Apr 2012 06:31:57 -0400
From: Tom Murphy <[email protected]>
Subject: Re: [Haskell-beginners] cmath Install troubles
To: Brandon Allbery <[email protected]>
Cc: beginners <[email protected]>
Message-ID:
<cao9q0twq1ocjs35wzdzmhen144tfgcfrbddxjk86_v0qvlu...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
On 4/19/12, Brandon Allbery <[email protected]> wrote:
> On Wed, Apr 18, 2012 at 21:39, Tom Murphy <[email protected]> wrote:
>
>> On 4/18/12, Brandon Allbery <[email protected]> wrote:
>> > On Wed, Apr 18, 2012 at 16:18, Tom Murphy <[email protected]> wrote:
>> >> This makes it seem like cabal doesn't have access to _any_ math.h
>> >> file, but if this were the case, wouldn't I get many more
>> >> undefined-function errors than I do?
>> >
>> > Unless you are using an older ghc with -fvia-C,
>> [...]
>> I have 7.0.4.
>>
>
> 7.0.4 has -fasm by default, but you can force -fvia-C still. With -fasm,
> the include files are not used afaik; since direct assembly code is created
> and not C code, a C include file is not useful.
>
>
>> Hmm, that's true...
>> I don't really understand how .hsc files are compiled, but isn't the
>> "#include <math.h>" in cmath done in the very standard FFI style?
>>
>
> If warnings are on, I think that elicits a "this is not used any more"
> warning with -fasm.
>
So does nobody use cmath anymore? I'm trying to install the latest
version (which is from 2008).
Tom
------------------------------
Message: 2
Date: Thu, 19 Apr 2012 15:42:20 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Cross-platform .hs files on Linux
and
Windows
To: [email protected], Vinay Sajip <[email protected]>,
"Henk-Jan van Tuyl" <[email protected]>
Message-ID: <[email protected]>
Content-Type: Text/Plain; charset="iso-8859-1"
On Wednesday 18 April 2012, 15:16:52, Vinay Sajip wrote:
> Henk-Jan van Tuyl <hjgtuyl <at> chello.nl> writes:
> > I've already tried that; if I use Notepad to convert the file to
> > UTF-8, GHC does not accept the shebang.
That's by design. GHC treats a shebang line as a comment *if the shebang is
the very first bytes of the file*.
With a BOM, the shebang isn't the start of the file, so it's not treated as
a comment.
You might change the ticket to a feature request.
------------------------------
Message: 3
Date: Thu, 19 Apr 2012 14:35:32 +0000 (UTC)
From: Vinay Sajip <[email protected]>
Subject: Re: [Haskell-beginners] Cross-platform .hs files on Linux
and
Windows
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
Daniel Fischer <daniel.is.fischer <at> googlemail.com> writes:
> That's by design. GHC treats a shebang line as a comment *if the shebang is
> the very first bytes of the file*.
> With a BOM, the shebang isn't the start of the file, so it's not treated as
> a comment.
>
> You might change the ticket to a feature request.
>
I'll leave it to the Trac administrators to handle as they see fit, but I find
it hard to believe this is "by design". Of course, tools like Notepad can be
viewed as a little broken because they prepend the BOM, but that's behaviour
that can't be completely avoided on Windows. It seems easy enough to check for a
BOM and skip that, because the BOM is not strictly part of the file contents;
it's just a marker indicating the encoding. The shebang line in the non-working
example is the very first thing in the file's actual contents (e.g. as
interpreted by Notepad).
Of course, for UTF-16/UCS-2 encoded files (also common on Windows), wouldn't the
compiler need to check for a BOM anyway?
Regards,
Vinay Sajip
------------------------------
Message: 4
Date: Thu, 19 Apr 2012 09:04:23 -0700
From: Tim Perry <[email protected]>
Subject: Re: [Haskell-beginners] Program reliability and multiple data
constructors; polymorphism
To: [email protected]
Message-ID:
<CAFVgASWanFt=eZQizLoRRBtcJ_g-AoM+NKhL=yKM=t7bxba...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
On Wed, Apr 18, 2012 at 8:10 AM, umptious <[email protected]> wrote:
> One of the programming exercises I keep evolving as I learn Haskell is a
> toy 2D shape editor with four primitives:
>
> data Shape = Circle {origin::Pt2, radius::Float}
> | Square {origin::Pt2, side ::Float}
> | Rect {origin::Pt2, other ::Pt2}
> | Composite {shapes::[Shape]}
> deriving (Show, Read)
>
> The intent is Composites can contain Shapes of any kind, including other
> Composites so that you can apply transformations to a Composite and these
> will be applied to the contained Shapes recursively. So an arm might
> contain a hand which constains a dozen or so Rects. Transform the arm and
> the hand and rects should transform; transform the hand and its rects
> should transform but the not arm. Big deal.
>
> And the above makes that really easy when you know you're talking to a
> Composite. But now I've hit an intellectual stumbling point and the books
> and source I have don't seem to address it: I can apply the destructuring
> command "shapes" defined in the cstr "Composite" to ANY Shape. And if I do
> that to say a circle, BLAM! Or if I apply "radius" to Rect, BLAM! At
> runtime. No type checking support (because yes, they're the same type.)
>
Well, if you have a Shape, you do not know what data type you have and
neither does the compiler. However, you can code a function, say shapeList,
which always gives you a list of Shapes regardless of what type of Shape
gets past in:
shapeList :: Shape -> [Shape]
shapeList (Composite shapes) = shapes
shapeList s = [s]
Lesson: don't use record syntax on a heterogeneous collection. I'm
surprised the compiler doesn't complain when record syntax
isn't guaranteed to succeed.
As a general comment, it looks like you are trying to code C++ or Java
style OO code in Haskell. I can say from experience, it doesn't work well.
Generally, envision your functions to work on a class of abstract data
types (ATDs). Generalize this class of ATDs into a typeclass. Write an
instance of the function to operate on each ADT you want to be a member of
a typeclass. So, if I was going to write some code to handle shapes I might
do it like the following. Be warned, I'm far from a Haskell Guru, but I
think this is a better approach. Hopefully we'll get an improved bit of
code....
import Data.List
data Pt2 = Pt2 { x :: Float , y :: Float } deriving (Show, Read)
data Circle = Circle { originCircle :: Pt2 , radius :: Float } deriving
(Show, Read)
data Square = Square { originSquare ::Pt2 , side :: Float } deriving
(Show, Read)
data Rect = Rect {originRect ::Pt2, other :: Pt2} deriving (Show, Read)
data Composite = Composite { circles :: [Circle]
, squares :: [Square]
, rects :: [Rect]
}
class Shape a where
area :: a -> Float
minx :: a -> Float
miny :: a -> Float
instance Shape Circle where
area (Circle _ r) = r * r * pi
minx (Circle (Pt2 x _) r) = x - r
miny (Circle (Pt2 _ y) r) = y - r
instance Shape Square where
area (Square _ side) = side*side
minx (Square (Pt2 x y) side) = if side < 0
then x + side
else x
miny (Square (Pt2 x y) side) = if side < 0
then y + side
else y
instance Shape Rect where
area (Rect (Pt2 x1 y1) (Pt2 x2 y2)) = abs((x2 - x1) * (y2 - y1))
minx (Rect (Pt2 x1 y1) (Pt2 x2 y2)) = min x1 x2
miny (Rect (Pt2 x1 y1) (Pt2 x2 y2)) = min y1 y2
instance Shape Composite where
area (Composite cs ss rs) = (sum $ map area cs) + (sum $ map area ss) +
(sum $ map area rs)
minx (Composite cs ss rs) = Data.List.minimum(map minx cs ++ map minx ss
++ map minx rs)
miny (Composite cs ss rs) = Data.List.minimum(map miny cs ++ map miny ss
++ map miny rs)
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120419/fbcdf509/attachment-0001.htm>
------------------------------
Message: 5
Date: Thu, 19 Apr 2012 23:17:13 +0300
From: Nikita Beloglazov <[email protected]>
Subject: Re: [Haskell-beginners] Training tasks
To: [email protected]
Message-ID:
<cajdg_pvpmzzleujnsaj4pmk53xyhbi9qqema4kfmm7tpwgv...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
>
> Yes, I get that. It's a bad idea. Showing atypical "promotional" cases for
> each language encourages faddishness and silver bullet cults; it's
> irresponsible and unprofessional. If you're shopping around for a language
> then nothing is worse than selected sweet spot cases. Unless they are a
> fair-ish benchmark for a language that excels in a clear area, like R, APL
> and Awk and you're looking for a glorified DSL.
>
> I'd say that its better to have the same tasks for each language if you're
> evaluating a general purpose tool. Obvious ones would be, from simple to
> complex:
>
> - Some of the unix command line utilities like wc (some of these might be
> single liners)
>
> - OXO, Caesar cipher (10 lines or so)
>
> - The Markov chain program from the Practice Of Programming
>
> - Life
>
> - A simple spheres only ray tracer like the one in Graham's Lisp book
>
> - A simple calculator program like the one in Hutton
>
> - The recursive 2D shape program I've mentioned in other posts today
>
> - A version of the classic Traveller/Elite trading system - a really nice
> little toy business rules system that can be code either minimally or to
> show off the funkier features of a language to get more flexibility and
> more interesting pricing rules. Minimal version would be a few tens of
> lines and the config file declaring items.
>
> If you want to see a language comparison done responsibly, look at
> Kernighan and Pike's "Practice Of Programming."
Thank you for criticism and tasks examples.
But I still think it isn't such a bad idea. Because if somebody get excited
about some language (even if it is based on "promotional" cases) and he
learns this language more by himself then it's great. I don't think
somebody will judge about whole language by few tasks. He may get
interested or dislike the language, but I doubt there will be silver bullet
cult based on few tasks.
By shopping language I mean choosing some new fun language to learn, not to
solve particular practical task.
Nikita
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120419/bdfcbe41/attachment-0001.htm>
------------------------------
Message: 6
Date: Thu, 19 Apr 2012 16:26:36 -0400
From: Brandon Allbery <[email protected]>
Subject: Re: [Haskell-beginners] Cross-platform .hs files on Linux and
Windows
To: Vinay Sajip <[email protected]>
Cc: [email protected]
Message-ID:
<cakfcl4wu4krq6+3po_ckjtndeteb8ngamoayfaddzasgsht...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Thu, Apr 19, 2012 at 10:35, Vinay Sajip <[email protected]> wrote:
> Of course, for UTF-16/UCS-2 encoded files (also common on Windows),
> wouldn't the
> compiler need to check for a BOM anyway?
>
I don't think GHC makes any attempt to suport UTF16 source.
--
brandon s allbery [email protected]
wandering unix systems administrator (available) (412) 475-9364 vm/sms
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120419/cde8d53a/attachment.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 46, Issue 34
*****************************************