Re: [Haskell-cafe] [Newbie] Quest for inheritance

2005-06-09 Thread Cédric Paternotte
On 6/6/05, Gracjan Polak [EMAIL PROTECTED] wrote:
 If you stick to single inheritance there is other way to simulate OO in
 Haskell. Look for phantom types. Whole wxHaskell (for example) is
 based on this concept.

I heard about them indeed but barely found clear explanations of it.
Any useful pointer you're aware of maybe ?

Cédric
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Space questions about intern and sets

2005-06-09 Thread Gracjan Polak

Udo Stenzel wrote:

Gracjan Polak wrote:


iorefset :: Ord a = IORef(Map.Map a a)
iorefset = unsafePerformIO $ do
   newIORef $ Map.empty


I could have as many dictionaries as there are types. The problem is I 
get one dictionary for each object which defeats the idea.



I believe the (Ord a) constraint acts like a function argument.
Therefore iorefset is no CAF, cannot be memoized itself and you get one
dictionary per invocation.  On the other hand, that is what is to be
expected when playing games with unsafePerformIO.


Seems you are right. Monomorphic type works, polymorphic doesn't. But it 
probably is not in any way guaranteed to stay like this in future.




You might get it working by giving iorefset a monomorphic type or by
specializing it for the type(s) you are using it at.  Don't forget the
NOINLINE pragma.  I wouldn't do it this way, though.  If you're parsing,
chances are that your code is monadic anyway.  Put a StateT over the
parser monad and everything works without black magic.  Even better, if
you're using parsec you can just put the Map in the user state.



This will create intern-per-parse, which isn't bad and has it's 
advantages, but I wanted to do something global. Anyway it was 
interesting experiment :)




Udo.


--
Gracjan
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] A reference manual for the Haskell monad functions

2005-06-09 Thread Henk-Jan van Tuyl


L.S.,

I have written a reference manual for the most common Haskell monad  
functions, in the

style of A Tour of the Haskell Prelude. It can be found at:
   http://members.chello.nl/hjgtuyl/tourdemonad.html


Known bug:
Not all keywords in the See also sections, that could be links, are
links.

--
Met vriendelijke groet,
Henk-Jan van Tuyl
--

Using Opera's revolutionary e-mail client:  
https://secure.bmtmicro.com/opera/buy-opera.html?AID=789433


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] A Tool To Show Functions Relationship?

2005-06-09 Thread Josef Svenningsson
On 6/6/05, Dimitry Golubovsky [EMAIL PROTECTED] wrote:
 Does there exist a tool which given a Haskell source, shows functions
 that are mutually recursive (i. e. call each other, even via calling
 third, etc. functions)? Knowledge of that would help to split the
 module into smaller modules without risk to create recursive modules.
 
When you sent this mail I seemed to recall a simple tool written by
Martin Nordbäck which could take a Haskell module an generate its call
graph. But when I searched the web for it I couldn't find it.
But to my surprise I found it today when wading through the heaps of
old Haskell code that I have around (looking for something completely
different.) I'm attaching it in the hope that you will find it useful.
It may have suffered from slight bit rot but it should be fairly easy
to get it up and running.

Cheers,

/Josef
-- Copyright (C) 2001 Safelogic AB
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
-- Last change: 2001-04-27

import HsParser
import HsParseMonad
import HsSyn
import List((\\), nub, partition)
import System
import Char(isAlphaNum)

parse_contents :: String - ParseResult HsModule
parse_contents contents = parse contents (SrcLoc 0 0) 0 []

main :: IO ()
main = do
  args - getArgs
  main' args

main' files = do
  contents - mapM readFile files
  let allPairs = map get_names contents
  let allnames = map fst (concat allPairs)
  putStr digraph call_graph {\n
  let (subgraphs,arrows) = unzip $ map (subgraph allnames) (zip3 (map show [1..]) files allPairs)
  putStr $ unlines $ subgraphs
  putStr $ unlines $ arrows
  putStr }

subgraph allnames (num,name,pairs) =
  let shown = [ (name, filter (\x - x `elem` allnames) vars) 
  | (name, vars) - pairs]
  in (subgraph cluster_ ++ num ++ {\n ++
 label=\ ++ name ++ \;\n ++
 unlines [ show_name name ++ ; | (name,_) - shown ] ++
 }\n,
 unlines (map show_arrows shown))

get_names contents =
  let result = parse_contents contents
  in  case result of
Failed string - error Parse failed: 
Ok _ (HsModule mod exports imports decls) - 
  let pairs = map (get_vars_decl []) decls
  -- The first in the pair is the function name, this function
	  -- returns a list, but there will only be one element in it.
	  pairs' = [(name,vars) | (name:[],vars) - pairs]
  -- combine all names which are doubled
  pairs'' = combine_firsts pairs'
  in pairs''

combine_firsts pairs = case pairs of
  [] - []
  (name, _):_ -
let (same_list, other_list) = partition (\(x,_) - x==name) pairs
in (name, nub (concatMap snd same_list)):combine_firsts other_list

show_arrows :: (HsName, [HsName]) - String
show_arrows (name, calls) = case calls of
  --[] - show_name name ++ ;\n
  _  - unlines [show_name name ++  -  ++ show_name call ++ ; 
| call - calls ]

show_name :: HsName - String
show_name name = case name of
  Qual (Module mod) string - fix_name (mod ++ _ ++ string)
  UnQual string - fix_name string

fix_name :: String - String
fix_name name = \ ++ name ++ \
-- fix_name name = map (\x - if isAlphaNum x || x == '_' then x else '_') name

get_vars_decls :: [HsName] - [HsDecl] - ([HsName], [HsName])
get_vars_decls ignore decls = 
  let (names,vars) = unzip (map (get_vars_decl ignore) decls)
  in (concat names, concat vars)

get_vars_decl :: [HsName] - HsDecl - ([HsName], [HsName])
get_vars_decl ignore decl = case decl of
  HsFunBind _ [HsMatch _ name pats rhs decls] - 
let patvars = concatMap get_vars_pat pats
vars = get_vars_rhs (ignore++patvars) rhs ++ 
   snd (get_vars_decls (ignore++patvars) decls)
in ([name], nub vars) 
  HsPatBind _ pat rhs decls - 
let vars = get_vars_rhs ignore rhs ++
   snd (get_vars_decls (ignore++names) decls)
names = get_vars_pat pat
in (names, nub vars)
  _ - ([],[])

get_vars_rhs :: [HsName] - HsRhs - [HsName]
get_vars_rhs ignore rhs = case rhs of
HsUnGuardedRhs exp - get_vars_exp ignore exp
HsGuardedRhss guardedrhss - 
  concatMap (get_vars_guardedrhs ignore) guardedrhss

get_vars_guardedrhs :: [HsName] - HsGuardedRhs - [HsName]
get_vars_guardedrhs ignore rhs = case rhs of
  HsGuardedRhs _ e1 e2 - get_vars_exps ignore [e1,e2]

get_vars_exps :: [HsName] - [HsExp] - [HsName]
get_vars_exps ignore exps = concatMap (get_vars_exp ignore) exps

get_vars_exp :: [HsName] - HsExp - [HsName]
get_vars_exp ignore exp = case exp of
  HsVar name  - if name `elem` ignore then [] else [name]
  HsInfixApp e1 e2 e3 - get_vars_exps ignore [e1,e2,e3]
  HsApp e1 e2 - get_vars_exps ignore [e1,e2]
  HsNegApp e  - get_vars_exp ignore e
  HsLambda _ e- get_vars_exp ignore e
  HsLet decls e   - 
let (ignores,vars) = get_vars_decls (ignores++ignore) decls
in 

Re: [Haskell-cafe] A reference manual for the Haskell monad functions

2005-06-09 Thread Frank-Andre Riess
 L.S.,
(B
(B I have written a reference manual for the most common Haskell monad
(B functions, in the
(B style of "A Tour of the Haskell Prelude". It can be found at:
(B http://members.chello.nl/hjgtuyl/tourdemonad.html
(B
(B
(B Known bug:
(B Not all keywords in the "See also" sections, that could be links, are
(B links.
(B
(BNice :)
(B
(BReading over it once, I noticed that you confused the types of () and (=).
(BDidn't see any other mistake, though.
(B
(BGreets,
(BFrank-Andre Riess
(B___
(BHaskell-Cafe mailing list
(BHaskell-Cafe@haskell.org
(Bhttp://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] A Tool To Show Functions Relationship?

2005-06-09 Thread Thomas Hallgren

Dimitry Golubovsky wrote:


Does there exist a tool which given a Haskell source, shows functions
that are mutually recursive (i. e. call each other, even via calling
third, etc. functions)?

With pfe, the Programmatica tools command line interface, you can 
currently get a list of definition level dependencies like this 
(assuming your module is called Example):


% pfesetup +h Example.hs
% pfe deps Example

module DepExample:
 declarator:
   Text.ParserCombinators.Parsec.Prim.?
   Text.ParserCombinators.Parsec.Prim.try
   Hugs.Prelude.Monad Hugs.Prelude.= pointer idd
   Text.ParserCombinators.Parsec.Prim.many cpi
   Hugs.Prelude.return Declarator
   
Text.ParserCombinators.Parsec.Prim.inst__Text_ParserCombinators_Parsec_Prim_Monad__l_GenParser_tok_st_r_
 idd:
   Text.ParserCombinators.Parsec.Prim.?
   Text.ParserCombinators.Parsec.Prim.|
   Text.ParserCombinators.Parsec.Prim.try
   Hugs.Prelude.Monad Hugs.Prelude.= anyIdString
   Hugs.Prelude.return Hugs.Prelude.Either
   Hugs.Prelude.Left Hugs.Prelude. tkOp declarator
   Hugs.Prelude.Right
   
Text.ParserCombinators.Parsec.Prim.inst__Text_ParserCombinators_Parsec_Prim_Monad__l_GenParser_tok_st_r_
 ...
 

The dependency information is computed after type checking, so it 
includes dependencies on instance declarations (which are assign names 
starting with inst__).


I guess it would be usesful to also have an option to eliminate 
dependencies on imported stuff, and an option to display mutually 
recursive groups (strongly connected components of definitions).



Knowledge of that would help to split the
module into smaller modules without risk to create recursive modules.
 

The Programatica tools actually support mutually recursive modules, so 
that wouldn't be a problem. We are still waiting for other Haskell 
implementations to catch up :-)


--
Thomas H


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] foldl and space problems

2005-06-09 Thread Samuel Bronson
On 06/06/05, Gracjan Polak [EMAIL PROTECTED] wrote:
 
 Question: is there any way to see what is holding my source list? I did
 try to guess, but without results as of now:(
 
 How do I debug and/or reason about such situation?

I heard that NHC has excellent heap profiling support, maybe it would
be able to help?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Looking for lost library

2005-06-09 Thread Dean Herington

At 7:23 PM -0400 6/9/05, Samuel Bronson wrote:

On 05/06/05, Dean Herington [EMAIL PROTECTED] wrote:

 I believe you're describing:
 http://portal.acm.org/citation.cfm?doid=581478.581482 .


I don't suppose you know of any place to get it *free*?


I found it online at: http://www.cse.ogi.edu/~magnus/papers/icfp-2002.pdf .
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe