Alson Kemp | 1 Mar 2006 01:26
Gravatar

Help with Type Class

  Although the discussion about Array refactoring died
down quickly on the Haskell' mailing list, I've been
noodling on refactoring the various Collections in
Haskell.  In doing so, I've bumped into a problem with
type classes that I can't resolve.  The issue is as
follows:

  I'm designing a Collections class heirarchy that is
a blend between that of Java and of Haskell. The
problem is that, whereas in OOP it is easy to do so,
Haskell class mechanism seems to make it difficult to
add *new* member variable to subclasses.

  Simple goal: create a top-level Collection with an
*indexed* Array subclass (and various other
subclasses).  The problem I'm running into is
Collection has no need of an "index" variable and I
can't seem to figure out how to add an "index" to
Array when subclassing from Collection  Mock up:

--
  class CollectionClass c e where
    -- every Collection supports toList...
    toList :: c e -> [e]

  class (CollectionClass a e)=> ArrayClass a e where
...

  data Array i e = Array i i 

(Continue reading)

ihope | 1 Mar 2006 02:06
Picon

My piece of an IRC bot

Today I started on a simple IRC bot framework thingy. I decided to
post the source code here so people can look at it and tell me what
the heck I did wrong :-P

> module IRC where
>
> import Control.Monad.State
> import System.IO
> import Network
>
> {----------------------}{------------------------------------------------------}
>
> data IRCMessage         = IRCMessage (Maybe String) String [String]
>
> type IRCBot a           = IRCMessage -> State a [IRCMessage]
> type IRCConnection a    = IRCBot a -> IO ()
>
> ircConnect              :: String -> Integer -> a -> IRCConnection a
>
> ircConnect server port
>               state bot = withSocketsDo (do
>   connection <- connectTo server (PortNumber (fromInteger port))
>  ircLoop connection state bot)
>
> ircLoop connection state
>                     bot = do
>   eof <- hIsEOF connection
>   if eof then hWaitForInput connection 500 >> return () else do
>     message <- hGetLine connection
>     hPutStr connection (fst (runState (bot (ircParseMessage message)) state) >>=
(Continue reading)

Brian Hulley | 1 Mar 2006 02:36

Re: Layout rule (was Re: PrefixMap: code review request)

Ben Rudiak-Gould wrote:
> Brian Hulley wrote:
>> Here is my proposed layout rule:
>>
>> 1) All layout keywords (where, of, let, do) must either be followed
>> by a single element of the corresponding block type, and explicit
>> block introduced by '{', or a layout block whose first line starts
>> on the *next* line
>
> I wouldn't have much trouble adapting to that.
>
>> and whose indentation is accomplished *only* by tabs
>
> You can't be serious. This would cause far more problems than the
> current rule.

Why? Surely typing one tab is better than having to hit the spacebar 4 (or 
8) times?

>
>> I would also make it that explicit braces are not allowed to switch
>> off the layout rule (ie they can be used within a layout),
>
> I don't understand. What does "used within a layout" mean?

I meant that {;} would be used just like any other construct that has to 
respect the layout rule so you could write

       let
            a = let { b = 6; z = 77;
(Continue reading)

Philippa Cowderoy | 1 Mar 2006 02:43

Re: Layout rule (was Re: PrefixMap: code review request)

On Wed, 1 Mar 2006, Brian Hulley wrote:

> Ben Rudiak-Gould wrote:
> > Brian Hulley wrote:
> > > Here is my proposed layout rule:
> > > 
<snip>
> > > and whose indentation is accomplished *only* by tabs
> > 
> > You can't be serious. This would cause far more problems than the
> > current rule.
> 
> Why? Surely typing one tab is better than having to hit the spacebar 4 (or 8)
> times?
> 

Not when it prevents me from ever exhibiting the slightest shred of style 
in my code. I use that control for readability purposes in my code.

--

-- 
flippa <at> flippac.org

"My religion says so" explains your beliefs. But it doesn't explain 
why I should hold them as well, let alone be restricted by them.
ajb | 1 Mar 2006 02:52
Favicon
Gravatar

Re: haskell programming guidelines

G'day all.

Quoting Christian Maeder <maeder <at> tzi.de>:

> I suggested:
>
>        f . g $ h x
>
> or
>        f $ g $ h x

Of these, the first version only makes sense if you want to single out h
for some reason.  I'm known to do this, for example, if h is a record
accessor.

The second is just plain wrong.  My reasoning is here for those who care:

    http://permalink.gmane.org/gmane.comp.lang.haskell.cafe/11256

Cheers,
Andrew Bromage
Jared Updike | 1 Mar 2006 03:14
Picon
Gravatar

Re: Layout rule (was Re: PrefixMap: code review request)

BH> > Why? Surely typing one tab is better than having to hit the
spacebar 4 (or 8)
BH> > times?
PC> Not when it prevents me from ever exhibiting the slightest shred of style
PC> in my code. I use that control for readability purposes in my code.
> [snip]

BH> I'm really puzled here. I've been using tabs to indent my C++ code for at
BH> least 10 years and don't see the problem.

At least two reasons:
1. C++ doesn't care about any whitespace (except to separate tokens).
Haskell cares about leading whitespace (which it is clear you are
thinking a lot about...) but
2. as Philippa mentioned, Haskell programmers care a ton about
inter-line, inter-word layout/alignment, for example, lining up =
signs and arguments to functions in pattern matches, etc. C++ does not
invite this style of declarative programming so it is not surprising
that it wasn't an issue: aside from the indentation, I rarely type
fancy whitespace inside a giving line of C++ code to align elements
with those on a preceding line. In Haskell, this unofficial layout
"style" doesn't affect the machine-parsing of the code, but rather the
human-parsing of the code. (In fact, it's one of my favorite things
about Haskell.)

If you want to see what can be accomplished with variable width fonts
and complex layouts (not just beginning of lines but rather
inter-line, inter-word alignment) you should checkout lhs2TeX. They
accomplish all their magic with spaces.

(Continue reading)

Johannes Ahlmann | 1 Mar 2006 04:06
Picon

mediawiki syntax highlighting plugins

hi,

i've noted that the new haskellwiki has dropped syntax highlighting
support for haskell code fragments. while i think that full highlighting
might be overkill, at least different color markup of code and comments
would certainly be nice.

investigating the options for syntax highlighting in mediawiki i found
the following two extensions using GNU enscript:

http://www.wickle.com/wiki/index.php/Syntax_Highlight_extension
http://www.milab.is.tsukuba.ac.jp/~bushuhui/index.php?title=Enhanced_syntax_highlight_extension_for_MediaWiki

where the second is an alteration of the first, with haskell support
already added.

an alternative would be geshi (http://qbnz.com/highlighter/) for which a
mediawiki plugin also exists
(http://meta.wikimedia.org/wiki/GeSHiHighlight), but it says on the
geshi site "GeSHi supports PHP5 and Windows". and i'm not clear whether
they mean it _also_ supports those options or exclusively.

it would be cool if one of the wiki maintainers could look into this
matter and possibly install/setup one of the above extensions.

thank you,

Johannes Ahlmann
Donald Bruce Stewart | 1 Mar 2006 05:02
Picon
Picon
Favicon
Gravatar

Code snippet, a `trace' with line and column numbers

Suggested by a question from sethk on #haskell irc channel. 
Solves an FAQ where people have often resorted to cpp or m4:
a `trace' that prints line numbers.    

> module Location (trace, assert) where
> 
> import qualified Control.Exception as C (catch)
> import System.IO.Unsafe  (unsafePerformIO)
> import GHC.Base          (assert)
> import System.IO
> 
> -- An identity function that also prints the current line and column number
> trace :: (Bool -> IO () -> IO ()) -> a -> a
> trace assrt f = (unsafePerformIO $ C.catch (assrt False $ return ()) printIt) `seq` f
>     where 
>       printIt e = let (x,_) = break (== ' ') $ show e 
>                   in hPutStrLn stderr (x ++ " trace")

for example:

> import Location
> 
> main = do
>     let x = trace assert (1+2) 
> 
>     putStrLn . show $ x

Generates:

$ ./a.out 
(Continue reading)

Ketil Malde | 1 Mar 2006 08:41
Picon
Picon

Re: Layout rule

"Brian Hulley" <brianh <at> metamilk.com> writes:

>> You can't be serious. This would cause far more problems than the
>> current rule.

> Why? Surely typing one tab is better than having to hit the spacebar 4
> (or 8) times?

What you type depends on your editor.  I hit tab, and the editor
inserts an appropriate number of spaces.  (I thought all editors did
this now?)

> There was an example posted on another thread where someone had got
> into confusion by using ; after a let binding in a do construct with
> an explicit brace after the 'do' but not after the 'let' (sorry I
> can't find it again).

> If you allow {- everything becomes a lot
> more complicated and who needs them anyway?

Multi line comments are nice for commenting out blocks of code.  It is
much less intrusive, in particular if you're using version control.

> back to editing a function at the top of a file. Things like {- would
> mean that all the parse trees for everything after it would have to be
> discarded. Also, flashing of highlighting on this scale could be very
> annoying for a user, so I'd rather just delete this particular
> possibility of the user getting annoyed when using my software :-)

Couldn't your editor just be a little bit smarter?  E.g. count the {-s
(Continue reading)

Jason Dagit | 1 Mar 2006 09:11
Picon
Favicon

Re: mediawiki syntax highlighting plugins

On 2/28/06, Johannes Ahlmann <softpro <at> gmx.net> wrote:
> hi,
>
> i've noted that the new haskellwiki has dropped syntax highlighting
> support for haskell code fragments. while i think that full highlighting
> might be overkill, at least different color markup of code and comments
> would certainly be nice.
>
> investigating the options for syntax highlighting in mediawiki i found
> the following two extensions using GNU enscript:
>
> http://www.wickle.com/wiki/index.php/Syntax_Highlight_extension

I'm no fan of enscript.  I tried it in the past and found it to be lacking.

> http://www.milab.is.tsukuba.ac.jp/~bushuhui/index.php?title=Enhanced_syntax_highlight_extension_for_MediaWiki
>
> where the second is an alteration of the first, with haskell support
> already added.
>
> an alternative would be geshi (http://qbnz.com/highlighter/) for which a
> mediawiki plugin also exists
> (http://meta.wikimedia.org/wiki/GeSHiHighlight), but it says on the
> geshi site "GeSHi supports PHP5 and Windows". and i'm not clear whether
> they mean it _also_ supports those options or exclusively.

It works in linux with php4 I know this because my website uses it:
http://codersbase.com/index.php/Geshi_haskell

I haven't gotten around to sending a copy to the geshi devs.  Feel
(Continue reading)


Gmane