Re: Haskell for non-Haskell's sake

2003-08-30 Thread gilesb
Hi Hal (et al.)

I am using it to write a compiler and interpretor for a quantum
programming language, based on the semantics of the paper by Peter
Selinger. (See
http://quasar.mathstat.uottawa.ca/~selinger/papers.html#qpl for details
on the semantics) 


On 29 Aug, Hal Daume III wrote:
> Hi fellow Haskellers,
> 
> If you use Haskell for a purpose *other than* one of those listed below,
> I'd love to hear.  I don't need a long report, anything from a simple "I
> do" to a paragraph would be fine, and if you want to remain anonymous
> that's fine, too.
> 
> Purposes which I consider "Haskell for Haskell's sake" include:
> 
>   - writing Haskell compilers/interpreters
>   - developing libraries for Haskell
>   - writing Haskell debuggers, tracers, profilers or other tools
>   - more or less anything with matches /.*Haskell.*/, other than
> /in Haskell$/   :)
> 

-- 
Brett G. Giles
Grad Student, University of Calgary
Formal Methods, Category Theory, Semantics of Programming
http://www.cpsc.ucalgary.ca/~gilesb mailto:[EMAIL PROTECTED]

___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell


Re: Hash in Haskell

2003-06-16 Thread gilesb
Typically, such functions are often used to implement mappings from
something (such as a String) to something else. 

If that is what you want take a  look at the type FiniteMap under the
Data area of GHC and HUGS. It implements all the needed functionality
without having to worry about creating a Hash for the keys.

If you want if for some other reason, you would typically need to define
a class such as:

Class Hash where
   hash::a->Int

and then implement it on your desired types. Strings are ususally
somewhat easy to create a unique has value, other types will, naturally,
depend on what is in them.



On 16 Jun, Sergio Sebastián Giro wrote:
> Hi, I need some function in Haskell to hash any value from any type to
> Int. I guess that such a function needs to be a primitive, but I don't
> found it in Hugs. Do you know how I can implement it or found it?
> Thanks
> Sergio
> ___
> Haskell mailing list
> [EMAIL PROTECTED]
> http://www.haskell.org/mailman/listinfo/haskell

-- 
Brett G. Giles
Grad Student, University of Calgary
Formal Methods, Category Theory, Semantics of Programming
http://www.cpsc.ucalgary.ca/~gilesb mailto:[EMAIL PROTECTED]

___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell


Re: Question About lists

2002-12-30 Thread gilesb
Hi Cesar

If you check the prelude, you will find the definition (something like):

length::[a]->Int
length= foldl' (\n _ -> n + 1) 0

and the definition of foldl'

foldl'   :: (a -> b -> a) -> a -> [b] -> a
foldl' f a [] = a
foldl' f a (x:xs) = (foldl' f $! f a x) xs

Which also gives a linear complexity (O(n)) to length.

Unless your representation of lists stores the length, you will pretty
much always need linear time to find out the length as you have to count
how many items there are.  

Alternatively, if getting the length is something you need to do a lot,
consider creating your own datatype and corresponding class for inserts
etc. that keeps the length on hand. This could allow O(1) length
queries.

On 30 Dec, Cesar Augusto Acosta Minoli wrote:
> 
> Hello! I'm Working with Lists in Haskell, I´m a Beginner in Functional 
>Programming and I would like to know if there is a way to write a more efficient 
>function that return the length of a list, I wrote this one:
> long    ::  [a]->Intlong 
>p =  longitud p 
>0  
> 
>where  
> longitud []   
>s=s  
> longitud (x:xs) s=longitud xs (s+1)
> but I think that it have a lineal grow O(n).
> thanks!
>  
>  
>  
>  Add photos to your e-mail with 
>MSN 8.  http://g.msn.com/8HMEEN/2021";>Get 3 months FREE*. 
> ___
> Haskell mailing list
> [EMAIL PROTECTED]
> http://www.haskell.org/mailman/listinfo/haskell

-- 
Brett G. Giles
Grad Student, University of Calgary
Formal Methods, Category Theory, Semantics of Programming
http://www.cpsc.ucalgary.ca/~gilesb mailto:[EMAIL PROTECTED]

___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell