[Haskell-cafe] matching types in Haskell

2009-08-13 Thread pat browne
Hi, I wish to align or match some Haskell types in order to represent a set of ontologies and their embedded concpts [1]. I am not sure wheather modules or classes could be used. I have done this task in a language called Maude[2]. The code is below. I appreciate that Maude is not very popular so

[Haskell-cafe] matching

2007-12-05 Thread Ryan Bloor
hi I have a matching problem... I am wanting to identify whether or not a string is an opening substring of another (ignoring leading spaces). I have this: word is a single word and str is a string. match :: String - String - (Bool, String)match word str | if removeSpace

Re: [Haskell-cafe] matching

2007-12-05 Thread Luke Palmer
Just remove that if. What comes after | is already a conditional. Luke On Dec 6, 2007 7:03 AM, Ryan Bloor [EMAIL PROTECTED] wrote: hi I have a matching problem... I am wanting to identify whether or not a string is an opening substring of another (ignoring leading spaces). I have this:

Re: [Haskell-cafe] matching

2007-12-05 Thread Luke Palmer
Oops, not quite. otherwise == should be otherwise =. Looks like you already go this from the first one, but guard syntax looks like: defn | cond1 = ... | cond2 = ... | ... | otherwise = ... (otherwise is not actually necessary; it is just a synonym for True) Luke On Dec 6, 2007 7:09

[Haskell-cafe] Matching constructors

2006-02-10 Thread Creighton Hogg
Hi, If I have something like data Patootie = Pa Int | Tootie Int and I want to pull out the indices of all elements of a list that have type constructor Tootie, how would I do that? I thought I might be able to use findIndices, but I don't know how to express the predicate.

Re: [Haskell-cafe] Matching constructors

2006-02-10 Thread J. Garrett Morris
tootieIndices = findIndices isTootie where isTootie (Pa _) = False isTootie (Tootie _) = True would be my first approach. /g On 2/10/06, Creighton Hogg [EMAIL PROTECTED] wrote: Hi, If I have something like data Patootie = Pa Int | Tootie Int and I want to pull out the

Re: [Haskell-cafe] Matching constructors

2006-02-10 Thread Henning Thielemann
On Fri, 10 Feb 2006, Creighton Hogg wrote: Hi, If I have something like data Patootie = Pa Int | Tootie Int and I want to pull out the indices of all elements of a list that have type constructor Tootie, how would I do that? I thought I might be able to use findIndices, but I don't know

Re: [Haskell-cafe] Matching constructors

2006-02-10 Thread Jared Updike
Or inline as findIndices (\x - case x of Tootie _ - True; _ - False) listOfPasAndTooties There was a recent thread about wanting a more succint way to write this (unary pattern matching): http://thread.gmane.org/gmane.comp.lang.haskell.cafe/11109 If John got his wish, then you could write

Re: [Haskell-cafe] Matching constructors

2006-02-10 Thread Mark T.B. Carroll
Creighton Hogg [EMAIL PROTECTED] writes: data Patootie = Pa Int | Tootie Int and I want to pull out the indices of all elements of a list that have type constructor Tootie, how would I do that? x = [Pa 3, Tootie 5, Pa 7, Tootie 9, Pa 11] y = [ i |Tootie i - x ] z = [ i | i@(Tootie _) -

Re: [Haskell-cafe] Matching constructors

2006-02-10 Thread Cale Gibbard
On 10/02/06, Creighton Hogg [EMAIL PROTECTED] wrote: Hi, If I have something like data Patootie = Pa Int | Tootie Int and I want to pull out the indices of all elements of a list that have type constructor Tootie, how would I do that? I thought I might be able to use findIndices, but I

Re: [Haskell-cafe] matching constructors

2004-03-08 Thread Vadim Zaliva
On Mar 5, 2004, at 15:48, Vadim Zaliva wrote: OK, I figured it out. For sake of other novices like me here is what you need to do to make it work. 0. Need to import Data.Generics 1. Compile with '-fglasgow-exts' flag 2. When deriving from Data you also need to derive from Typeable. It slightly

Re: [Haskell-cafe] matching constructors

2004-03-08 Thread Sven Panne
Vadim Zaliva wrote: [...] It slightly bothers me that this solution seems to be using non-standard GHC extensions. Hmmm, using generics seems like massive overkill for option handling. Could you describe what you are exactly trying to achieve? Cheers, S.

Re: [Haskell-cafe] matching constructors

2004-03-08 Thread Vadim Zaliva
On Mar 8, 2004, at 11:17, Sven Panne wrote: Hmmm, using generics seems like massive overkill for option handling. Could you describe what you are exactly trying to achieve? I am doing command line options parsing. I've defined Flag type with constructor for each possible option: data Flag =

Re: [Haskell-cafe] matching constructors

2004-03-08 Thread Ben Rudiak-Gould
On Mon, 8 Mar 2004, Vadim Zaliva wrote: I am doing command line options parsing. I've defined Flag type with constructor for each possible option: data Flag = Verbose | Input String | Output String | Filter String deriving (Show,

Re: [Haskell-cafe] matching constructors

2004-03-08 Thread Vadim Zaliva
On Mar 8, 2004, at 12:55, Ben Rudiak-Gould wrote: This would work, but I will have to write [] part for each option. Generics approach is overkill but looks much neater when used. But thanks for suggestion anyway, it is always good to learn yet another way of doing things. Sincerely, Vadim Try

[Haskell-cafe] matching constructors

2004-03-05 Thread Vadim Zaliva
Hi! I am new to Haskell, but I have background in various programming languages (including Lisp) I have very basic question, if there is a way to match algebraic types constructors besides use of pattern matching. I wrote today code like this: data Flag = Verbose | Input String |

Re: [Haskell-cafe] matching constructors

2004-03-05 Thread Brandon Michael Moore
On Fri, 5 Mar 2004, Vadim Zaliva wrote: Hi! I am new to Haskell, but I have background in various programming languages (including Lisp) I have very basic question, if there is a way to match algebraic types constructors besides use of pattern matching. I wrote today code like this: