a function which return the type of element

Dear All ; I look for the function which return the type of un element in Haskell : For example If type(a) = Int then f else g Regards

There are several possibilities. The one that maps most closely to the expression you wrote is:
import Data.Typeable(typeOf) if typeOf a == typeOf (undefined :: Int) then f else g
Of course, f and g must have the same type. See http://haskell.org/ghc/docs/latest/html/libraries/base-3.0.0.0/Data-Typeable... for more details. Dan BOUNEB ZINE EL ABIDINE wrote:
Dear All ;
I look for the function which return the type of un element in Haskell :
For example
If type(a) = Int then f else g
Regards

2007/11/16, BOUNEB ZINE EL ABIDINE
I look for the function which return the type of un element in Haskell : For example If type(a) = Int then f else g
Pourquoi poser une question en anglais sur haskell-_fr_ ?? Il y a plusieurs façon de faire ce que tu demandes sans avoir besoin d'une telle fonction, par exemple les typeclass, mais d'abord j'aimerais savoir pourquoi tu penses en avoir besoin, il est très rare qu'on ait vraiment besoin de ceci dans un programme normal. -- Jedaï

Merci sur votre courier , et je demande pardon sur l'anglais, mon objectif
et de développer un langage orienté objet et fonctionnelle, je vais faire
une translation d'un langage de haut niveau qui support les notions de
l'orienté objet implicitement typé vers un langage qui est purement
fonctionnelle et avec un typage explicite , comme la notion du type class en
Haskell et je veut faire comme première étape une translation d'un exemple
de type class. merci
-----Original Message-----
From: haskell-fr-bounces@haskell.org [mailto:haskell-fr-bounces@haskell.org]
On Behalf Of Chaddaï Fouché
Sent: vendredi 16 novembre 2007 11:39
To: La liste Haskell Francophone
Subject: Re: [Haskell-fr] a function which return the type of element
2007/11/16, BOUNEB ZINE EL ABIDINE
I look for the function which return the type of un element in Haskell : For example If type(a) = Int then f else g
Pourquoi poser une question en anglais sur haskell-_fr_ ?? Il y a plusieurs façon de faire ce que tu demandes sans avoir besoin d'une telle fonction, par exemple les typeclass, mais d'abord j'aimerais savoir pourquoi tu penses en avoir besoin, il est très rare qu'on ait vraiment besoin de ceci dans un programme normal. -- Jedaï _______________________________________________ Haskell-fr mailing list Haskell-fr@haskell.org http://www.haskell.org/mailman/listinfo/haskell-fr

Prière aussi d'excuser ma réponse en anglais. En général, j'essaie de répondre dans la même langue que celle de la question posée. Si tu es content de poser tes questions (et d'y recevoir les réponses) en anglais, tu trouveras une communauté beaucoup plus vaste et plus diverse à la liste haskell-cafe@haskell.org. Dan BOUNEB ZINE EL ABIDINE wrote:
Merci sur votre courier , et je demande pardon sur l'anglais, mon objectif et de développer un langage orienté objet et fonctionnelle, je vais faire une translation d'un langage de haut niveau qui support les notions de l'orienté objet implicitement typé vers un langage qui est purement fonctionnelle et avec un typage explicite , comme la notion du type class en Haskell et je veut faire comme première étape une translation d'un exemple de type class. merci
-----Original Message----- From: haskell-fr-bounces@haskell.org [mailto:haskell-fr-bounces@haskell.org] On Behalf Of Chaddaï Fouché Sent: vendredi 16 novembre 2007 11:39 To: La liste Haskell Francophone Subject: Re: [Haskell-fr] a function which return the type of element
2007/11/16, BOUNEB ZINE EL ABIDINE
: I look for the function which return the type of un element in Haskell : For example If type(a) = Int then f else g
Pourquoi poser une question en anglais sur haskell-_fr_ ?? Il y a plusieurs façon de faire ce que tu demandes sans avoir besoin d'une telle fonction, par exemple les typeclass, mais d'abord j'aimerais savoir pourquoi tu penses en avoir besoin, il est très rare qu'on ait vraiment besoin de ceci dans un programme normal.

--- BOUNEB ZINE EL ABIDINE
I look for the function which return the type of un element in Haskell :
For example
If type(a) = Int then f else g
Hello,I am Dan P. and I try to answer: If you want to get different effects, let's say different expression being evaluated according to the TYPE of the entity involved you may try to use: - a class - some instances of that class, every one having it's own definition of 'type' Let's start: Let's suppose f and g are two functions. First of all you can try to define your own class: class MyClass a b c where type :: a -> (b->c) So, for every element of type a, the value of type(a) will be a function. Let's suppose we know the signatures of f and g: something like (the same for both f and g) f:: Float -> Char g:: Float -> Char ----------------------------------------------------- | TO define the behaviour of type for a being an Int| | YOU HAVE TO INSTANTIATE the class MyClass and tell| | how can type will work ! | ----------------------------------------------------- instance MyClass Int Float Char where type _ = f For the other types (you did not specify them,sorry) for example for String other instances can be defined: instance MyClass String Float Char where type _ = g In this way the function 'type' became a polimorphically overrloaded function. -------------------------------------------- Simplified version. f::X and g :: X , X being a specific type. class SimpleClass a where type :: a -> X instance SimpleClass Int where type _ = f instance SimpleClass Char where type _ = g and so one for other types which can be the type of a. ----------------------------------------------- May be more solutions. Let's hope this will help. Dan ____________________________________________________________________________________ Be a better pen pal. Text or chat with friends inside Yahoo! Mail. See how. http://overview.mail.yahoo.com/

Salut à tous! Ouf... Ca y est! Je vous l'avais promis pour Noël, ça a pris un peu de retard... Mais il est là! J'ai fini la traduction du tutorial "Haskell for the C programmers". C'est une approche très attractive d'Haskell, puisque ça s'adresse à l'immense majorité des developpeurs: les gens qui connaissent uniquement la programmation impérative (comme moi il y a peu). J'attend donc vos relectures, pour ceux qui veulent bien s'y coller: - orthographe - grammaire - style - organisation et bien sur les erreurs sur le fond, car je ne suis qu'un débutant en Haskell! Je suis également très mauvais en orthographe, c'est une catastrophe. Pour le style, le style de l'auteur était plutôt lourd... J'ai essayé d'améliorer les choses mais il y a certainement encore du boulot. Tout est sujet à modification, même le titre du doc... J'ai choisis le format word pour l'édition. Si vous éditez le doc lui-même, surlignez vos modifs en jaune. Vous pouvez également ajouter les "commentaires" word (sorte de post-it). Pour vos remarques globales, vous pouvez les mettre dans un doc à part, ou dans un mail (mon mail figure dans le doc). ftp://ftp-developpez.com/corentin-du...ammeur%20C.doc L'original: http://www.haskell.org/~pairwise/intro/intro.html Merci! Je tiens à remercier spécialement Nicolas Vallée pour son aide. Corentin
participants (5)
-
BOUNEB ZINE EL ABIDINE
-
Chaddaï Fouché
-
Dan Popa
-
Dan Weston
-
Dupont Corentin