Re: [Haskell-cafe] Substituting values

2012-12-25 Thread Radical
Hey Petr,

On Sat, Dec 22, 2012 at 9:52 AM, Petr P  wrote:
>
> I think you need something wha Scala has - the ability to create a partial
> function from a case expression. In Scala you could write
>
>   def update[A](f: PartialFunction[A,A])(v: A): A =
> f.orElse({ case x => x } : PartialFunction[A,A]).apply(v);
>
> and then use it like
>
>   update[Int]({ case Foo => Bar })
>


Thanks for the pointer. One distinction I remember from dabbling in Scala
some years ago is that Scala seems to formalize partiality whereas, if I'm
not mistaken, Haskell doesn't (though perhaps there are libraries that let
you do that). That is, to me a partial function in Haskell is almost
uniformly an error, whereas in Scala it's a somewhat common pattern.


> But AFAIK there is nothing like this in Haskell. Maybe separating 'of'
> from 'case' would be the way to extend Haskell with such a feature <
> http://www.haskell.org/pipermail/haskell-cafe/2012-November/104884.html>
>
>>
Does Haskell have a way to query at runtime whether a function is partial?
(Not in the full sense, since it would be necessary to prove totality, but
in the sense that a case expression is not exhaustive.) Otherwise, I'm not
sure how you could use a partial lambda without reaching `undefined`. (I
guess you could catch the exception.)

Thanks,

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


Re: [Haskell-cafe] Substituting values

2012-12-24 Thread Radical
Yeah, I guess I was wondering whether something like it already existed.
Thinking about it some more, perhaps what I want is `tr` [1]. E.g.

  tr [Foo] [Bar]

Incorporating your suggestion would then yield a more general version like:

  trBy (== Foo) Bar



[1] http://en.wikipedia.org/wiki/Tr_(Unix)


On Sat, Dec 22, 2012 at 6:46 AM, David Thomas wrote:

> Seems like the function is easy to define:
>
> replaceIfEq a b c = if c == a then b else c
>
> Then the above can be written
>
>replaceIfEq Foo Bar value
>
> Or the slightly more general (in exchange for slightly more verbosity at
> the call site)
>
> replaceIf p r a = if p a then r else a
>
>replaceIf (== Foo) Bar value
>
>
>
>
> On Fri, Dec 21, 2012 at 6:46 PM, Radical  wrote:
>
>> Sometimes I'll need something like:
>>
>>   if value == Foo then Bar else value
>>
>> Or some syntactic variation thereof:
>>
>>   case value of { Foo -> Bar; _ -> value }
>>
>> Is there a better/shorter way to do it? I'm surprised that it's more
>> complicated to substitute a value on its own than e.g. in a list, using
>> filter. Or perhaps I'm missing the right abstraction?
>>
>> Thanks,
>>
>> Alvaro
>>
>>
>>
>>
>> ___
>> 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] Substituting values

2012-12-24 Thread Radical
On Sat, Dec 22, 2012 at 12:35 AM, Kim-Ee Yeoh  wrote:

> This is reminiscent of the Either (exception) monad where Left values, the
> exceptions, pass through unaltered, and Right values are transformable,
> i.e. acted on by functions.
>
>
Interesting. I hadn't thought of that parallel. But yes, I think it's a
similar notion of: transform the value only in one (or more) cases. It's
also similar to the Maybe monad in that I'm looking for something akin to
fromMaybe, but without having to place the value in a Maybe.


> But I have no idea what you're trying to achieve in the bigger picture.
> Help us help you by fleshing out your use case.
>
>
I'm not sure the bigger picture is helpful, but, for example, the last case
was something like:

  if ch == '\n' then ' ' else ch

I think I ended up rewriting it as something like:

  replace '\n' = ' '
  replace ch = ch

Which is straightforward enough, though it feels to me like there's too
much syntax involved.

Thanks,

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


[Haskell-cafe] Substituting values

2012-12-21 Thread Radical
Sometimes I'll need something like:

  if value == Foo then Bar else value

Or some syntactic variation thereof:

  case value of { Foo -> Bar; _ -> value }

Is there a better/shorter way to do it? I'm surprised that it's more
complicated to substitute a value on its own than e.g. in a list, using
filter. Or perhaps I'm missing the right abstraction?

Thanks,

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


Re: [Haskell-cafe] Hoogle index completeness

2012-12-20 Thread Radical
Thanks for the suggestion, Jan. Is there a way to include all of hackage?

Alvaro


On Thu, Dec 20, 2012 at 3:37 AM, Jan Stolarek wrote:

> > I see that the comments are from years ago. Are there any ongoing efforts
> > to expand the default search set? (Or alternatively, to implement the
> > +hackage modifier mentioned.)
> It's actually implemented as +nameOfLibrary. Hoogling for "rstrip
> +missingh" gives:
>
> rstrip :: String -> String
> MissingH Data.String.Utils
> Same as strip, but applies only to the right side of the string.
>
> Janek
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Hoogle index completeness

2012-12-19 Thread Radical
Thanks, Petr.

I see that the comments are from years ago. Are there any ongoing efforts
to expand the default search set? (Or alternatively, to implement the
+hackage modifier mentioned.)

Is there interest in either of these things happening?

Alvaro




On Wed, Dec 19, 2012 at 12:06 PM, Petr P  wrote:

>   Hi Alvaro,
>
> by default Hoogle only searches some standard set of packages, which is
> only a relatively small subset of all Hackage content. From
> http://www.haskell.org/haskellwiki/Hoogle#Scope_of_Web_Searches :
>
> > Using the standard web interface, Hoogle searches: array, arrows, base,
> bytestring, Cabal, cgi, containers, directory, filepath, haskell-src,
> HUnit, mtl, old-locale, old-time, packedstring, parallel, parsec, pretty,
> process, QuickCheck, random, stm, template-haskell, time, xhtml.
>
> See http://www.haskell.org/haskellwiki/Hoogle/Packages
>
> One solution is to install Hoogle locally and let it index all packages
> you have installed.
>
> Best regards,
> Petr
>
>
> 2012/12/19 Radical 
>
>> Searching Hoogle for symbols like `rstrip` or `lstrip` produces "No
>> results found" for me, even though they exist in the MissingH library.
>> To wit:
>> http://hackage.haskell.org/packages/archive/MissingH/1.2.0.0/doc/html/Data-String-Utils.html
>>
>> Is this behavior intentional, or a regression of some sort? I could
>> have sworn the above symbols showed up at some point.
>>
>> Thanks!
>>
>> Alvaro
>>
>> ___
>> 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] Hoogle index completeness

2012-12-19 Thread Radical
Searching Hoogle for symbols like `rstrip` or `lstrip` produces "No
results found" for me, even though they exist in the MissingH library.
To wit: 
http://hackage.haskell.org/packages/archive/MissingH/1.2.0.0/doc/html/Data-String-Utils.html

Is this behavior intentional, or a regression of some sort? I could
have sworn the above symbols showed up at some point.

Thanks!

Alvaro

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