Re: [Haskell-cafe] Best practices for Arrows?

2013-06-23 Thread Ertugrul Söylemez
Tom Ellis tom-lists-haskell-cafe-2...@jaguarpaw.co.uk wrote:

 Unfortunately my type doesn't have a Monad instance.

If you could reveal the type, we could give more precise suggestions.


  In most cases when you expose an `Arrow` interface you can also
  expose a `Category`+`Applicative` interface, which is pretty much
  equivalent (except for a few extra laws):
 
  proc x - do
  y1 - a1 - x
  y2 - a2 - x
  id - x + y1 + y2^2
 
  Is equivalent to:
 
  liftA3 (\x y1 y2 - x + y1 + y2^2) id a1 a2

 Yes, I can see how that would be useful.  My question is: are you
 talking about this Applicative instance:

 data MyArr a b = ...

 instance Arrow MyArr where
 ...

 instance Functor (MyArr a) where
   fmap f = (arr f )

 instance Applicative (MyArr a) where
   pure = arr . const
   f * g = arr (uncurry ($))  (f  g)

Yes, that seems right.


 I think I will be able to make my Arrow an ArrowLoop, but I haven't
 checked.

It's not that your type may have a useful or even sensible ArrowLoop
notion, but if it does, then arrow notation is very useful.  Also as
Ross noted it gives you access to some additional convenience syntax, in
particular if your type is an ArrowChoice.  Those combinators are
extremely awkward to use directly, but proc notation allows you to use
regular if/case syntax.

However, even then sometimes it can be beneficial to use composition of
small self-contained arrow formulas.


Greets,
Ertugrul

-- 
Not to be or to be and (not to be or to be and (not to be or to be and
(not to be or to be and ... that is the list monad.


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


Re: [Haskell-cafe] Help me understand general recursion from cata- and anamorphism

2013-06-23 Thread Takayuki Muranushi
Dear all,

https://github.com/nushio3/practice/blob/master/recursion-schemes/FibTest.hs

After learning fix-point operators, I found an answer by myself.

```

fibBase :: (Integer - Integer) - Integer - Integer
fibBase fib n
  | n = 1= 1
  | otherwise = fib (n-1) + fib (n-2)

fibWithFix :: Integer - Integer
fibWithFix = fix fibBase
```

I can say `fibBase` is free of recursion, despite the facts that apparently
it uses a name `fib` on RHS which it binds on the LHS, and that the entire
structure seems very similar to the recursive version of `fib` .



2013/6/16 Takayuki Muranushi muranu...@gmail.com

 In an attempt to understand why cata- and anamorphisms are considered so
 important, I found multiple implications that you can write any recursive
 functions in terms of nonrecursive functions and ana, cata (am I right
 here?) so I'm trying to practice the rewrite by a few functions. I'm
 following a recipe found here:

 http://lambda-the-ultimate.org/node/4290

 ~~~
 Given a function that recurses on itself, do a partial CPS transform so
 that it only ever recurses on itself with tail calls. Then, convert the
 recursive calls to codata returns, so that the function either returns
 TheAnswer or StillWorking with enough parameters to describe the recursive
 call / continuation state. This codata can be built with an unfold and can
 be collapsed back down to the final answer with a fold.
 ~~~


 https://github.com/nushio3/practice/blob/master/lens/banana/CollatzTest.hs
 https://github.com/nushio3/practice/blob/master/lens/banana/FibTest.hs

 I find it difficult to understand the terminology, and the above attempts
 are only halfway done. I guess ( TheAnswer or StillWorking ) structure is
 the one found in iteratee/enumeratee. But I don't know how to build a
 codata with unfold.

 I'd appreciate any advice.

 Best,

 --
 Takayuki MURANUSHI
 The Hakubi Center for Advanced Research, Kyoto University
 http://www.hakubi.kyoto-u.ac.jp/02_mem/h22/muranushi.html




-- 
Takayuki MURANUSHI
The Hakubi Center for Advanced Research, Kyoto University
http://www.hakubi.kyoto-u.ac.jp/02_mem/h22/muranushi.html
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] putting the result of a function in `infix` declaration

2013-06-23 Thread TP
Hi everyone,

Consider the following code:

--
import Prelude hiding ((+))

data Expr = Plus Expr Expr | Minus Expr Expr | Expr String deriving Show

f :: Expr - Int
f (Plus _ _) = 1
f (Minus _ _) = 2

-- infix (f (Plus undefined undefined)) +  -- (*)
infix 6 +
(+) :: Expr - Expr - Expr
e1 + e2 = Plus e1 e2

main = do

let a = Expr a
let b = Expr b
print $ a + b
--

I would like to declare the infix precedence of (+) with a function 
(commented line (*)) instead of directly as above.

Is there any means to do that?
Do we need some kind of preprocessing machinery? How to do that in Haskell?

In a more general way, let us suppose I have a Haskell library able to 
perform some calculations: how to use it in a pre-processing step, before 
compilation of the executable? It could be a function to compute 
symbolically roots of a polynomial of second degree to be used at runtime. 
We would put some placeholders in the code where the result of the pre-
processing calculation would enter.

Thanks in advance,

TP


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


Re: [Haskell-cafe] tangential request...

2013-06-23 Thread Michael Orlitzky
On 06/22/2013 11:09 PM, Evan Laforge wrote:
 You're overthinking it.  I just sent a whole screen.
 

You're probably right; done.



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


Re: [Haskell-cafe] ANNOUNCE: haskell-names-0.1

2013-06-23 Thread AlanKim Zimmerman
I took a quick look at this, and came to the conclusion that the scope info
is available from GHC, but is not exposed by HaRe at this stage.

Rather than chasing something just to show it can be done, I am going to
use my limited time for HaRe.

By the way, I think buildwrapper generates a summary of a project as as
well, in JSON format.

Also, for GHC RenamedSource, querying any Name entity will provide the
package it came from (via
http://www.haskell.org/ghc/docs/7.6.3/html/libraries/ghc-7.6.3/Name.html#v:nameModule
)

e.g.

(Data.Generics.Text.gshow, syb-0.4.0:Data.Generics.Text),

Alan


On Fri, Jun 21, 2013 at 9:05 AM, AlanKim Zimmerman alan.z...@gmail.comwrote:

 I have a feeling the work-in-progress Haskell Refactorer using the GHC API
 may be able to provide this information through its library interface.

 When I have some time over the weekend I will have a look.

 Alan


 On Fri, Jun 21, 2013 at 8:44 AM, Michael Sloan mgsl...@gmail.com wrote:

 Roman: Awesome!  I'm really glad that this is ready for use!

 Andrew: I have a tool that's a step towards doing this.  Instead of using
 haskell suite, it uses ghci via hint to query module exports, and then uses
 TH to reify them.  This has the benefit of supporting everything that GHC
 supports, whereas there are currently some cases that haskell-src-exts
 can't parse.  There's also the issue of supporting declarations generated
 by template haskell.

 Here's an example of diffing some of its output:


 https://github.com/mgsloan/api-compat/blob/master/examples/template-haskell.api.diff

 The main reason I haven't released the tool is that I was intending to do
 structural diffs / handle renaming, so it's somewhat unfinished.  However I
 believe it's reasonably usable: instead, the output is just structured in a
 way that's reasonably amenable to diffing.

 -Michael


 On Thu, Jun 20, 2013 at 11:12 PM, Andrew Cowie 
 and...@operationaldynamics.com wrote:

 On Thu, 2013-06-20 at 18:13 +0300, Roman Cheplyaka wrote:
  Namely, it can do the following:
 
  *   for a module, compute its interface, i.e. the set of entities
  exported by the module, together with their original names.
 
  *   for each name in the module, figure out what it refers to — whether
  it's bound locally (say, by a where clause) or globally (and then
  give its origin).

 Is this a step toward being able to automatically derive an API version
 number [in the SO version sense of the word; ie, has a change happened
 requiring a version bump?]

 AfC
 Sydney


 ___
 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 mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] putting the result of a function in `infix` declaration

2013-06-23 Thread Karl Voelker
On Sun, Jun 23, 2013 at 6:36 AM, TP paratribulati...@free.fr wrote:

 In a more general way, let us suppose I have a Haskell library able to
 perform some calculations: how to use it in a pre-processing step, before
 compilation of the executable?


You are looking for Template Haskell.

http://www.haskell.org/haskellwiki/Template_Haskell

I'm not sure how up-to-date the wiki is, but it should give you the general
idea.

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


Re: [Haskell-cafe] putting the result of a function in `infix` declaration

2013-06-23 Thread Roel van Dijk
Related to Karl's Template Haskell suggestion you could also have a look at
quasiquotation:

http://www.haskell.org/haskellwiki/Quasiquotation

The GHC documentation has an example of a expression quoter:

http://www.haskell.org/ghc/docs/latest/html/users_guide/template-haskell.html#th-quasiquotation


On 23 June 2013 22:22, Karl Voelker ktvoel...@gmail.com wrote:

 On Sun, Jun 23, 2013 at 6:36 AM, TP paratribulati...@free.fr wrote:

 In a more general way, let us suppose I have a Haskell library able to
 perform some calculations: how to use it in a pre-processing step, before
 compilation of the executable?


 You are looking for Template Haskell.

 http://www.haskell.org/haskellwiki/Template_Haskell

 I'm not sure how up-to-date the wiki is, but it should give you the
 general idea.

 -Karl V.

 ___
 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] Fwd: How to make this data type work?

2013-06-23 Thread Magicloud Magiclouds
Thank you guys.

I cannot use a explicit type for there are quite a few of them. But from
MigMit, I understand why my original cannot work.


On Sat, Jun 22, 2013 at 4:46 AM, Vincent Ambo taz...@gmail.com wrote:

 Is there a reason why you can't use an explicit type variable?

 {-# LANGUAGE OverloadedStrings, ExistentialQuantification #-}

 import Data.Aeson
 import Control.Applicative
 import Control.Monad (mzero)

 data ActionData j
 = (FromJSON j, ToJSON j) = AD j j

 instance ToJSON (ActionData j) where
   toJSON (AD o n) = object [ oldData .= o
, newData .= n ]

 instance (ToJSON j, FromJSON j) = FromJSON (ActionData j) where
   parseJSON (Object v) = AD
 $ v .: oldData
 * v .: newData
   parseJSON _ = mzero


 2013/6/21 Miguel Mitrofanov miguelim...@yandex.ru

 Forgot to reply all, as usual.

  Пересылаемое сообщение  
 21.06.2013, 12:52, Miguel Mitrofanov miguelim...@yandex.ru:

 Actually, this is not the real error you should care about. Try removing
 FromJSON instance completely, and you'll get a lot more. And these are
 fundamental: you have to decide what j to use when serializing. Haskell
 won't automagically substitute some suitable type for you.

 So, that's a classic mismatch: for serializing (ToJSON) you need your j
 type to be known to the AD value (meaning: it should be quantified
 existentially), but for deserializing you need it to be any type
 (quantified universally).

 All in all, AD seems to be the wrong type.

 21.06.2013, 12:18, Magicloud Magiclouds magicloud.magiclo...@gmail.com
 :

   data ActionData = AD { oldData :: (FromJSON j, ToJSON j) = j
, newData :: (FromJSON j, ToJSON j) = j}
   instance ToJSON ActionData where
 toJSON (AD o n) = object [ oldData .= o
  , newData .= n ]
   instance FromJSON ActionData where
 parseJSON (Object v) = AD
   $ v .: oldData
   * v .: newData
 parseJSON _ = mzero
 
   I got when compile:
   No instance for (FromJSON (forall j. (FromJSON j, ToJSON j) = j))
 arising from a use of `.:'
   Possible fix:
 add an instance declaration for
 (FromJSON (forall j. (FromJSON j, ToJSON j) = j))
   In the second argument of `($)', namely `v .: oldData'
   In the first argument of `(*)', namely `AD $ v .: oldData'
   In the expression: AD $ v .: oldData * v .: newData
 
   --
   竹密岂妨流水过
   山高哪阻野云飞
 
   And for G+, please use magiclouds#gmail.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



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




-- 
竹密岂妨流水过
山高哪阻野云飞

And for G+, please use magiclouds#gmail.com.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] tangential request...

2013-06-23 Thread Mark Lentczner
Thanks all, I’ve got what I needed.

Brief results; Big variety in window and text sizes, but very few font and
color choices. More than half the terminals seem to be basically default
settings.

Finally, 15% seem to be using horrid bitmap console fonts. _How can you
stand to look at them?!?!_ (Don't worry, you'll have Plush soon enough...)
​
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe