Re: [Haskell-cafe] number-parameterized types and heterogeneous lists

2008-06-22 Thread Harald ROTTER
Hello,

sorry for the late answer, I was off for the weekend :-)

The paper "Number-parameterized types" by Oleg Kielyov is located at

  http://okmij.org/ftp/papers/number-parameterized-types.pdf

It impressively shows what one can do with Haskell's type system.
What I am after is the replacement of a "chain" of digits, like e.g.
  D1 $ D0 $ D0 $ Sz
by a list
  [D1,D0,D0]
so I can effectively use list operations on those "typed numbers". I also
wonder if there is some kind of
"generalized" foldr such that, e.g.
  D1 $ D0 $ D0 $ Sz = specialFoldr ($) Sz [D1,D0,D0]
I think that this foldr must be some "special" foldr that augments the data
type of the result in each foldr step.
Would this be possible or am I just chasing phantoms ?

Thanks

Harald.



" Ce courriel et les documents qui y sont attaches peuvent contenir des 
informations confidentielles. Si vous n'etes  pas le destinataire escompte, 
merci d'en informer l'expediteur immediatement et de detruire ce courriel  
ainsi que tous les documents attaches de votre systeme informatique. Toute 
divulgation, distribution ou copie du present courriel et des documents 
attaches sans autorisation prealable de son emetteur est interdite." 

" This e-mail and any attached documents may contain confidential or 
proprietary information. If you are not the intended recipient, please advise 
the sender immediately and delete this e-mail and all attached documents from 
your computer system. Any unauthorised disclosure, distribution or copying 
hereof is prohibited."
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Help with generalizing function

2008-06-22 Thread Bulat Ziganshin
Hello leledumbo,

Monday, June 23, 2008, 10:30:51 AM, you wrote:

> I've successfully create a function to return lists of N-ple that satisfy the

tuples may contain any combination of types, use lists instead

-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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


Re: [Haskell-cafe] Help with generalizing function

2008-06-22 Thread Ryan Ingram
Hint: use recursion.

Hint 2: You can use <- in a list comprehension or list "do"-block to
select a single list from a list of lists.

  -- ryan

On Sun, Jun 22, 2008 at 11:30 PM, leledumbo <[EMAIL PROTECTED]> wrote:
>
> I've successfully create a function to return lists of N-ple that satisfy the
> following function:
> x1 + x2 + x3 + ... + xN = C
> But unfortunately, it's not generic. The N is supposed to be an input, too.
> I don't know how to make a dynamic N-ple (is it possible anyway?).
> Currently, here's the implementation:
> [code]
> findAllAns c = [ (x1,x2,x3,x4,x5) |
>x1 <- [0..c],
>x2 <- [0..c],
>x3 <- [0..c],
>x4 <- [0..c],
>x5 <- [0..c],
>x1 + x2 + x3 + x4 + x5 == c
>  ]
> [/code]
> I tried using lists of lists, like this:
> [code]
> findAllAns c n = [ [x] | x <- [0..c], length [x] == n ]
> [/code]
> but [x] doesn't mean "a list of x", instead it's "a list that contains an x,
> where x in [0..c]". Can anyone help me?
> --
> View this message in context: 
> http://www.nabble.com/Help-with-generalizing-function-tp18063291p18063291.html
> Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] What is a rigid type variable?

2008-06-22 Thread Ryan Ingram
To answer the question in the subject:

>From "Simple unification-based type inference for GADTs",
Peyton-Jones, et al.  ICFP 2006.
http://research.microsoft.com/users/simonpj/papers/gadt/

"Instead of "user-specified type", we use the briefer term rigid
type to describe a type that is completely specified, in some
direct fashion, by a programmer-supplied type annotation."

So a rigid type is any type specified by a programmer type signature.
All other types are "wobbly".

Does anyone know what is going to change about the terminology with
the new "boxy types" paper?
http://research.microsoft.com/users/simonpj/papers/boxy/

  -- ryan

  -- ryan

On Sun, Jun 22, 2008 at 8:26 PM, Xiao-Yong Jin <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I'm writing a short function as follows, but I'm not able to
> find a suitable type signature for `go'.  It uses
> Numeric.LinearAlgebra from hmatrix.
>
>
> -- | Map each element in a vector to vectors and thus form a matrix
> -- | row by row
> mapVecToMat :: (Element a, Element b) =>
>   (a -> Vector b) -> Vector a -> Matrix b
> mapVecToMat f v = fromRows $ go (d - 1) []
>where
>  d = dim v
>  go :: Element b => Int -> [Vector b] -> [Vector b]
>  go 0 vs = f (v @> 0) : vs
>  go !j !vs = go (j - 1) (f (v @> j) : vs)
>
>
> If I give the type signature to go as this, I got the
> following error
>
>Couldn't match expected type `b1' against inferred type `b'
>  `b1' is a rigid type variable bound by
>   the type signature for `go' at test.hs:36:20
>  `b' is a rigid type variable bound by
>  the type signature for `mapVecToMat' at test.hs:31:35
>  Expected type: Vector b1
>  Inferred type: Vector b
>In the first argument of `(:)', namely `f (v @> 0)'
>In the expression: f (v @> 0) : vs
>
> So what is this rigid type variable all about and what is
> correct type of the function `go'?
>
> Thanks in advance,
> X-Y
> --
>c/*__o/*
><\ * (__
>*/\  <
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Help with generalizing function

2008-06-22 Thread leledumbo

I've successfully create a function to return lists of N-ple that satisfy the
following function:
x1 + x2 + x3 + ... + xN = C
But unfortunately, it's not generic. The N is supposed to be an input, too.
I don't know how to make a dynamic N-ple (is it possible anyway?).
Currently, here's the implementation:
[code]
findAllAns c = [ (x1,x2,x3,x4,x5) |
x1 <- [0..c],
x2 <- [0..c],
x3 <- [0..c],
x4 <- [0..c],
x5 <- [0..c],
x1 + x2 + x3 + x4 + x5 == c
  ]
[/code]
I tried using lists of lists, like this:
[code]
findAllAns c n = [ [x] | x <- [0..c], length [x] == n ]
[/code]
but [x] doesn't mean "a list of x", instead it's "a list that contains an x,
where x in [0..c]". Can anyone help me?
-- 
View this message in context: 
http://www.nabble.com/Help-with-generalizing-function-tp18063291p18063291.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


Re: [Haskell-cafe] What is a rigid type variable?

2008-06-22 Thread Luke Palmer
On Mon, Jun 23, 2008 at 5:58 AM, Luke Palmer <[EMAIL PROTECTED]> wrote:
> On Mon, Jun 23, 2008 at 3:26 AM, Xiao-Yong Jin <[EMAIL PROTECTED]> wrote:
>> Hi all,
>>
>> I'm writing a short function as follows, but I'm not able to
>> find a suitable type signature for `go'.  It uses
>> Numeric.LinearAlgebra from hmatrix.
>>
>>
>> -- | Map each element in a vector to vectors and thus form a matrix
>> -- | row by row
>> mapVecToMat :: (Element a, Element b) =>
>>   (a -> Vector b) -> Vector a -> Matrix b
>> mapVecToMat f v = fromRows $ go (d - 1) []
>>where
>>  d = dim v
>>  go :: Element b => Int -> [Vector b] -> [Vector b]
>>  go 0 vs = f (v @> 0) : vs
>>  go !j !vs = go (j - 1) (f (v @> j) : vs)
>
> If you want to give a type signature for 'go', you need a GHC
> extension called ScopeTypeVariables (IIRC).

I was indeed correct on the name of this extension, but it would be no
help to you to know this since I made a typo :-)

The extension is called ScopedTypeVaraibles.

You probably already know that this can be enabled with:

{-# LANGUAGE ScopedTypeVariables #-}

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


Re: [Haskell-cafe] What is a rigid type variable?

2008-06-22 Thread Luke Palmer
On Mon, Jun 23, 2008 at 3:26 AM, Xiao-Yong Jin <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I'm writing a short function as follows, but I'm not able to
> find a suitable type signature for `go'.  It uses
> Numeric.LinearAlgebra from hmatrix.
>
>
> -- | Map each element in a vector to vectors and thus form a matrix
> -- | row by row
> mapVecToMat :: (Element a, Element b) =>
>   (a -> Vector b) -> Vector a -> Matrix b
> mapVecToMat f v = fromRows $ go (d - 1) []
>where
>  d = dim v
>  go :: Element b => Int -> [Vector b] -> [Vector b]
>  go 0 vs = f (v @> 0) : vs
>  go !j !vs = go (j - 1) (f (v @> j) : vs)

If you want to give a type signature for 'go', you need a GHC
extension called ScopeTypeVariables (IIRC).  The problem is that the
'b' in the signature of mapVecToMat is not the same b as the one in
'go'.  With this extension, you can put those variables into scope for
the body of the definition using explicit 'forall' quantifiers:

mapVecToMat :: forall a b. (Element a, Element b) =>
   (a -> Vector b) -> Vector a -> Matrix b
-- rest as before

But the Element b constraint is redundant in the signature of 'go',
since that constraint is already in place by the above signature.

As far as I can tell, giving an explicit signature for 'go' is not
possible without this extension.

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


[Haskell-cafe] Planet haskell

2008-06-22 Thread Jamie Brandon
I was hoping to have my summer of code blog added to planet haskell
but [EMAIL PROTECTED] no longer seems to exist. Hopefully
the owner is subscribed to this list?

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


[Haskell-cafe] What is a rigid type variable?

2008-06-22 Thread Xiao-Yong Jin
Hi all,

I'm writing a short function as follows, but I'm not able to
find a suitable type signature for `go'.  It uses
Numeric.LinearAlgebra from hmatrix.


-- | Map each element in a vector to vectors and thus form a matrix
-- | row by row
mapVecToMat :: (Element a, Element b) =>
   (a -> Vector b) -> Vector a -> Matrix b
mapVecToMat f v = fromRows $ go (d - 1) []
where
  d = dim v
  go :: Element b => Int -> [Vector b] -> [Vector b]
  go 0 vs = f (v @> 0) : vs
  go !j !vs = go (j - 1) (f (v @> j) : vs)


If I give the type signature to go as this, I got the
following error

Couldn't match expected type `b1' against inferred type `b'
  `b1' is a rigid type variable bound by
   the type signature for `go' at test.hs:36:20
  `b' is a rigid type variable bound by
  the type signature for `mapVecToMat' at test.hs:31:35
  Expected type: Vector b1
  Inferred type: Vector b
In the first argument of `(:)', namely `f (v @> 0)'
In the expression: f (v @> 0) : vs

So what is this rigid type variable all about and what is
correct type of the function `go'?

Thanks in advance,
X-Y
-- 
c/*__o/*
<\ * (__
*/\  <
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Lambda and closures in PHP -- could someone please comment?

2008-06-22 Thread Richard A. O'Keefe

This is increasingly less relevant to Haskell, except
of course to demonstrate what a nice language Haskell is.
On 20 Jun 2008, at 11:34 pm, Jules Bean wrote:
I think where I differ on you is how to map the semantics of a C- 
like language to explicit references.


I would argue that the glyph "c" in a C-like language denotes the  
value of C, not the reference to it. C-like languages have, for the  
most part, value semantics, and call-by-value.


The exception of course is what C-like languages called "lvalues",  
but lvalues are only really on the left of the = sign and a few  
other special positions. I think that's the exception and not the  
rule.


No, this is back to front.  C basically follows the Algol 68 idea that
the lvalue is the normative thing, and that there is an IMPLICIT  
COERCION

from a variable to its value in certain contexts.  C is full of implicit
coercions: perhaps the most famous is the one that says that in almost  
all

contexts an array is quietly coerced to a pointer to its first element.

The key observation is that an implicit coercion from a variable to its
contents is possible, whereas an implicit coercion from a value to "the"
variable that holds it is not.   Only the "a variable really stands for
its address" view is coherent.

In C, of course, if you want to capture the reference you do it  
explicitly with "&c".


If we can use evidence from a relative to probe such questions,
the fact that you *don't* need an explicit "&" in C++ (when you find a  
'reference'
to a variable, you use "c", not "&c") strongly suggests that the  
"variable stands

for location" view is the more useful one.

Thankfully, Haskell saves us these perplexities.
(And replaces them with other perplexities...)

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


Re: [Haskell-cafe] INVITATION

2008-06-22 Thread Don Stewart
james:
> Haskell Hall wrote:
> > Haskell Hall is up and running. Haskell Hall is a mailing list, a 
> forum, where you can discuss Haskell, functional programming and 
> anything related, freely and openly with fellow enthusiasts. We welcome 
> people of all abilities and know-how. So, if you fancy a change from 
> what you get on Haskell Cafe send an email to 
> [EMAIL PROTECTED] with the word subscribe in the subject 
> field.The first 10 members will have access to the wine cellar. :-)
> 
> 
> How does or will Haskell Hall differ?
> 
> I.e., why would I want to join another list?

This is a list set up by PR Stanley after he was moderated last week,
during a flame war in this channel.

http://thread.gmane.org/gmane.comp.lang.haskell.cafe/41413/focus=41444

Make of that what you will.

-- Don

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


Re: [Haskell-cafe] INVITATION

2008-06-22 Thread James Britt

Haskell Hall wrote:
> Haskell Hall is up and running. Haskell Hall is a mailing list, a 
forum, where you can discuss Haskell, functional programming and 
anything related, freely and openly with fellow enthusiasts. We welcome 
people of all abilities and know-how. So, if you fancy a change from 
what you get on Haskell Cafe send an email to 
[EMAIL PROTECTED] with the word subscribe in the subject 
field.The first 10 members will have access to the wine cellar. :-)



How does or will Haskell Hall differ?

I.e., why would I want to join another list?




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


Re: [Haskell-cafe] Safe way to parse arguments?

2008-06-22 Thread Henning Thielemann


On Sat, 21 Jun 2008, Xiao-Yong Jin wrote:


Hi,

I'm wondering how usually you parse command line arguments
list safely.  If the given argument is wrong, the program
can still print out some error information instead of giving
something like

Prelude.read: no parse


It's generally not a good idea to call 'read' on user data. 'read' expects 
well-formed input. Calling 'read' with other input is a programming 
_error_. If the user enters garbage, this is an _exception_ and this must 
be handled with 'reads' or 'maybeRead' as others suggested.

 http://www.haskell.org/haskellwiki/Error
 http://www.haskell.org/haskellwiki/Exception

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


Re: [Haskell-cafe] another FFI question

2008-06-22 Thread Niels Aan de Brugh
On Sat, 2008-06-21 at 00:20 +0400, Bulat Ziganshin wrote:
> 
> probably, you don't understand differences between OOP classes and
> type classes. look at http://haskell.org/haskellwiki/OOP_vs_type_classes
> and papers mentioned there

I took the liberty to update some of the C++ code on that page so that
the code will compile and work as expected.

Reading the rest of the page I have a question regarding section 4.2,
Type classes correspond to parameterized abstract classes (Gabriel Dos
Reis). This is probably more related to C++ than Haskell, so not all
readers might find it of interest.



--- off topic ---

Looking at 4.2, it's interesting to see how type classes are translated
into C++. Admittedly C++ isn't the prettiest language to look at, but I
feel one must be fair, and the code presented at the Wiki is too
complex, using virtuals and templates where they're not needed. Normal
overloading suffices.

Operator definitions can already be placed outside of a class scope,
e.g. the many overloads of << to print something to a stream. By default
these definitions cannot access private members of their operands but
the code at the Wiki has the same problem.

Just a small example:

// --- somewhere in a file ---
struct Aap {
int x;
explicit Aap(int x) : x(x) {}
Aap add(Aap const& other) const { return Aap(x + other.x); }
};

// --- somewhere in another file ---
Aap operator+(Aap const& lhs, Aap const& rhs) {
return lhs.add(rhs);
}

Overloading functions is not different. I've omitted some other (more
complex) ways you can achieve the same (aside from normal overloads it's
also allowed to introduce new specializations later).

At the time of writing it's not possible in C++ to restrict a type to
allow a certain operation (concepts[1] will hopefully fill that gap some
day, but I think it'll be a long time before tool support is ready for
prime-time). Rather, it's common to just use the operation and let the
compiler generate a (sometimes very cryptic) error message if it cannot
find the right code.
[1]: http://www.generic-programming.org/software/ConceptGCC/

A very poor man's solution to see if an operation is defined would be:

template struct has_add;
template<> struct has_add {};
int main() {
(void)sizeof(has_add); // okay
(void)sizeof(has_add); // fails to compile, put useful comment
here
}

It's not hard to add some primitive predicate logic (at compile time) to
resemble type classes in some sense, but I think this is off-topic
enough as it is.

Regards,
Niels


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


Re: [Haskell-cafe] ieee 754

2008-06-22 Thread Henning Thielemann


On Sun, 22 Jun 2008, Lennart Augustsson wrote:


Haskell does not allow you to change rounding mode, NaN signallng mode, etc.
But otherwise Haskell on modern platforms conforms to IEEE 754.


It just uses the machine floating point implementation, which is most 
oftenly IEEE. However the good news are - if someone manually writes 
functions for IEEE number representation, they could be used exactly the 
same way as Float and Double, and chances are good that with some 
optimizer RULES the operations can be replaced by efficient FPU operations 
on IEEE compliant FPUs.

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


[Haskell-cafe] INVITATION

2008-06-22 Thread Haskell Hall

Haskell Hall is up and running. Haskell Hall is a mailing list, a forum, where 
you can discuss Haskell, functional programming and anything related, freely 
and openly with fellow enthusiasts. We welcome people of all abilities and 
know-how. So, if you fancy a change from what you get on Haskell Cafe send an 
email to [EMAIL PROTECTED] with the word subscribe in the subject field.The 
first 10 members will have access to the wine cellar. :-)
_
The i’m Talkathon starts 6/24/08.  For now, give amongst yourselves.
http://www.imtalkathon.com?source=TXT_EML_WLH_LearnMore_GiveAmongst___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Testing

2008-06-22 Thread Haskell Hall

Testing Testing
_
Need to know now? Get instant answers with Windows Live Messenger.
http://www.windowslive.com/messenger/connect_your_way.html?ocid=TXT_TAGLM_WL_Refresh_messenger_062008___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Scripting OpenOffice with Haskell

2008-06-22 Thread Henning Thielemann


Has someone already tried to communicate with OpenOffice via Haskell? An 
interface seems to exist:

  http://framework.openoffice.org/scripting/index.html

For instance, I like to mark some cells in oocalc, preprocess them and 
write them to a database.

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


Re: [Haskell-cafe] ieee 754

2008-06-22 Thread Lennart Augustsson
Haskell does not allow you to change rounding mode, NaN signallng mode, etc.
But otherwise Haskell on modern platforms conforms to IEEE 754.

  -- Lennart

On Sun, Jun 22, 2008 at 9:37 AM, Sean McLaughlin <[EMAIL PROTECTED]> wrote:
> Hello,
>
>  I'm considering using Haskell for a numerical application.  However,
> I need to rely
> on IEEE 754 standards being implemented correctly.  What is the
> current state of 754 in Haskell?
> The definition has this paragraph, which makes me suspect Haskell is
> not appropriate for this
> application:
>
> "The default floating point operations defined by the Haskell Prelude
> do not conform to current language independent arithmetic (LIA)
> standards. These standards require considerably more complexity in the
> numeric structure and have thus been relegated to a library. Some, but
> not all, aspects of the IEEE floating point standard have been
> accounted for in Prelude class RealFloat."
>
> Thank you,
>
> Sean
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] ieee 754

2008-06-22 Thread Sean McLaughlin
Hello,

  I'm considering using Haskell for a numerical application.  However,
I need to rely
on IEEE 754 standards being implemented correctly.  What is the
current state of 754 in Haskell?
The definition has this paragraph, which makes me suspect Haskell is
not appropriate for this
application:

"The default floating point operations defined by the Haskell Prelude
do not conform to current language independent arithmetic (LIA)
standards. These standards require considerably more complexity in the
numeric structure and have thus been relegated to a library. Some, but
not all, aspects of the IEEE floating point standard have been
accounted for in Prelude class RealFloat."

Thank you,

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