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] Help me understand general recursion from cata- and anamorphism

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


Re: [Haskell-cafe] type-level integers for GHC

2013-05-20 Thread Takayuki Muranushi
Thank you everyone!
Iavor have kindly fixed the branch and now I can build it.

2013/5/20 Simon Peyton-Jones simo...@microsoft.com:
 The type-nats branch *should* simply work all by itself. (You may need to 
 check out a corresponding branch on some other repos, though.)

 Iavor would you care to comment?

 Simon

 Microsoft Research Limited (company number 03369488) is registered in England 
 and Wales
 Registered office 21 Station Road, Cambridge, CB1 2FB


 | -Original Message-
 | From: Christiaan Baaij [mailto:christiaan.ba...@gmail.com]
 | Sent: 20 May 2013 09:56
 | To: Takayuki Muranushi
 | Cc: Simon Peyton-Jones; haskell
 | Subject: Re: [Haskell-cafe] type-level integers for GHC
 |
 | What works best for me is to actually merge the type-nats branch into a
 | local checkout of master; as opposed to checking out the type-nats
 | branch.
 | Though you will usually have to do some (minor) conflict resolution.
 |
 | -- Christiaan
 |
 | On May 17, 2013, at 11:13 PM, Takayuki Muranushi muranu...@gmail.com
 | wrote:
 |
 |  Hey thanks Simon and Levor, I've reported the problem month ago, and I
 |  see today the commit-id for type-nats is still not changed. So I
 |  thought the problem remains. Let me first try the compile process
 |  again tonight, and report the compile process in more detail.
 | 
 |  2013/5/17 Simon Peyton-Jones simo...@microsoft.com:
 |  I wonder why you can't compile type-nats?  It should just work.  You
 |  could email ghc-devs and Iavor (type-nats author, cc'd) explaining
 |  exactly what goes wrong. You may need the type-nats branch of some
 |  libraries, I'm not sure
 | 
 |  Simon
 | 
 |  Microsoft Research Limited (company number 03369488) is registered in
 |  England and Wales Registered office 21 Station Road, Cambridge, CB1
 |  2FB
 | 
 | 
 |  | -Original Message-
 |  | From: haskell-cafe-boun...@haskell.org [mailto:haskell-cafe-
 |  | boun...@haskell.org] On Behalf Of Takayuki Muranushi
 |  | Sent: 17 May 2013 07:18
 |  | To: haskell
 |  | Subject: [Haskell-cafe] type-level integers for GHC
 |  |
 |  | What is your recommendation for type-level integers?
 |  |
 |  | I'd like to use it to improve the unittyped,
 |  | https://bitbucket.org/xnyhps/haskell-unittyped/ the library for
 |  | physical dimension. Therefore, I need negative numbers, additions,
 |  | but multiplications are not necessary.
 |  |
 |  | I've been looking forward for the type-nats extension of GHC, but I
 |  | haven't been able to compile the type-nats branch. Just learned
 |  | that it still takes a few month to merge the branch into the main.
 |  | http://hackage.haskell.org/trac/ghc/wiki/Status/May13
 |  |
 |  | Thijs, the original author of unittyped, has commited a branch that
 |  | uses type-nats, but I can't try that out for the same reason.
 |  |
 |  |
 |  | Best,
 |  | --
 |  | 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
 | 
 | 
 | 
 |  --
 |  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




-- 
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


Re: [Haskell-cafe] type-level integers for GHC

2013-05-18 Thread Takayuki Muranushi
Hey thanks Simon and Levor, I've reported the problem month ago, and I
see today the commit-id for type-nats is still not changed. So I
thought the problem remains. Let me first try the compile process
again tonight, and report the compile process in more detail.

2013/5/17 Simon Peyton-Jones simo...@microsoft.com:
 I wonder why you can't compile type-nats?  It should just work.  You could 
 email ghc-devs and Iavor (type-nats author, cc'd) explaining exactly what 
 goes wrong. You may need the type-nats branch of some libraries, I'm not sure

 Simon

 Microsoft Research Limited (company number 03369488) is registered in England 
 and Wales
 Registered office 21 Station Road, Cambridge, CB1 2FB


 | -Original Message-
 | From: haskell-cafe-boun...@haskell.org [mailto:haskell-cafe-
 | boun...@haskell.org] On Behalf Of Takayuki Muranushi
 | Sent: 17 May 2013 07:18
 | To: haskell
 | Subject: [Haskell-cafe] type-level integers for GHC
 |
 | What is your recommendation for type-level integers?
 |
 | I'd like to use it to improve the unittyped,
 | https://bitbucket.org/xnyhps/haskell-unittyped/ the library for physical
 | dimension. Therefore, I need negative numbers, additions, but
 | multiplications are not necessary.
 |
 | I've been looking forward for the type-nats extension of GHC, but I
 | haven't been able to compile the type-nats branch. Just learned that it
 | still takes a few month to merge the branch into the main.
 | http://hackage.haskell.org/trac/ghc/wiki/Status/May13
 |
 | Thijs, the original author of unittyped, has commited a branch that uses
 | type-nats, but I can't try that out for the same reason.
 |
 |
 | Best,
 | --
 | 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



-- 
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] type-level integers for GHC

2013-05-17 Thread Takayuki Muranushi
What is your recommendation for type-level integers?

I'd like to use it to improve the unittyped,
https://bitbucket.org/xnyhps/haskell-unittyped/ the library for
physical dimension. Therefore, I need negative numbers, additions, but
multiplications are not necessary.

I've been looking forward for the type-nats extension of GHC, but I
haven't been able to compile the type-nats branch. Just learned that
it still takes a few month to merge the branch into the main.
http://hackage.haskell.org/trac/ghc/wiki/Status/May13

Thijs, the original author of unittyped, has commited a branch that
uses type-nats, but I can't try that out for the same reason.


Best,
--
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] ghc head creates premature tarball

2013-04-10 Thread Takayuki Muranushi
Hi all,

These few days I've been having trouble in attempt to use GHC head. I
follow the following standard steps to create a tarball:

$ git clone http://darcs.haskell.org/ghc.git/
$ cd ghc
$ # optionally, git checkout branch name
$ ./sync-all --testsuite get
$ cp mk/build.mk.sample mk/build.mk
$ ### edit BuildFlavour to quick ###
$ ./boot
$ ./configure
$ make -jN # N is the number of cores you have.
$ make binary-dist

and then sandbox-install the tarball by hsenv. However, the installed
ghc exhibits the following strange behaviors:

(1) several .so files need to be manually copied to /usr/lib .
(2) the installed ghc doesn't find any package, even 'base' or 'ghc-prim'


Then carefully looking, I found that `make binary-dist` is outputting
some error messages,:

 cd bindistprep  /bin/tar hcf - -T ../bindist-list | bzip2 -c  
 ../bindistprep/ghc-7.7.20130409-x86_64-unknown-linux.tar.bz2
 /bin/tar: ghc-7.7.20130409/compiler/stage2/doc: Cannot stat: No such file or 
 directory
 /bin/tar: Exiting with failure status due to previous errors

The file ./bindist-list included a filepath that doesn't exist, so
that tar command aborted there and every item after that line on the
list was excluded from the tarball. So I tested the following trick;

$ touch compiler/stage2/doc

Then the previous error message didn't show up any more, and the
spurious behavior (1) (2) didn't appear any more.

I'm wondering if this is an installer bug or I was doing something
wrong. 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

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


[Haskell-cafe] Status of GHC type-nats branch

2013-02-25 Thread Takayuki Muranushi
Hi, everyone,

In order to merge two type-level key-value pairs
(More specifically, to use TypeNats branch of unittyped:
https://bitbucket.org/xnyhps/haskell-unittyped/commits/all/tip/branch%28%22TypeNats%22%29
)
I'd like to use overlapping type families and the type level Naturals
at the same time.

However, I couldn't build the type-nats branch of ghc, as I've been
trying this week.
I could build that in late 2012, so maybe this is due to updates in
the git submodules.

Do you reproduce this? Is there anyone else trying to build the
type-nats branch?

Any advice is helpful, including negative ones, if it's temporally
broken or no more supported. And, I'm particularly glad if anyone has
a x86-64 linux tarball of type-nats branch, and share it with me :)

Best regards,

--
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


Re: [Haskell-cafe] Status of GHC type-nats branch

2013-02-25 Thread Takayuki Muranushi
Thank you Iavor! I'm looking forward for the update.

Takayuki

2013/2/26 Iavor Diatchki iavor.diatc...@gmail.com:
 Hello,
 I haven't merged the type-nats branch with GHC master recently, so some of
 the libraries probably moved forward, which could be the source of the
 problem.  I'll make sure to fix it over the next couple of days.
 -Iavor


 On Mon, Feb 25, 2013 at 6:39 AM, Takayuki Muranushi muranu...@gmail.com
 wrote:

 Hi, everyone,

 In order to merge two type-level key-value pairs
 (More specifically, to use TypeNats branch of unittyped:

 https://bitbucket.org/xnyhps/haskell-unittyped/commits/all/tip/branch%28%22TypeNats%22%29
 )
 I'd like to use overlapping type families and the type level Naturals
 at the same time.

 However, I couldn't build the type-nats branch of ghc, as I've been
 trying this week.
 I could build that in late 2012, so maybe this is due to updates in
 the git submodules.

 Do you reproduce this? Is there anyone else trying to build the
 type-nats branch?

 Any advice is helpful, including negative ones, if it's temporally
 broken or no more supported. And, I'm particularly glad if anyone has
 a x86-64 linux tarball of type-nats branch, and share it with me :)

 Best regards,

 --
 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





--
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


Re: [Haskell-cafe] Lens, with ability to create a data-field when it's missing

2013-01-10 Thread Takayuki Muranushi
Dear everyone,

With help of many, I found ways to implement most of the features I
have wanted, and I can release the new dynamic-object package.
http://hackage.haskell.org/package/dynamic-object

Thank you in advance for your supports,

Takayuki

2013/1/3 Takayuki Muranushi muranu...@gmail.com:
 Dear All, I really am enjoying the lens (it is tough to learn, though :)

 Recently, I've been trying to implement a dynamic object --- a
 collection of methods that you can update at run-time --- using lens
 [1][2][3]. After several attempts, I think I have located the center
 of my problem:

 Lens with the ability to create a data-field when it's missing. My
 question: is it possible?

 There are many excellent examples of partial lenses in the lens
 library, such as '_head' from Data.List.Lens 'dynamic' from
 Data.Dynamic.Lens . To me, they seem to share the following set of
 common behavior (allow me to use inaccurate terms...)

 - set l a s : if the field is present, insert 'a'; otherwise, do nothing.
 - over l f s : if the field is present, map 'f' over it. otherwise, do 
 nothing.
 - preview l s : if the field is present, return 'Just a'. otherwise,
 return 'Nothing' .

 Instead, I want the following set of behaviors:

 - set l a s : if the field is present, insert 'a'; otherwise, *create
 the field* and insert 'a'.
 - over l f s : if the field is present, map 'f' over it. otherwise, do 
 nothing.
 - preview l s : if the field is present, return 'Just a'. otherwise,
 return 'Nothing' .

 For example, the current behavior of _head is
  []  _head .~ 1
 []
 I want to implement a variant _head' , such that
  []  _head' .~ 1
 [1]


 Let us call this behavior 'Member' for the moment.

 I have a implementation of 'Member' [4][5] but they are
 unsatisfactory. [4] involves runtime errors and breaking of lens laws.
 [5] shows that we can create a field only if we treat Dynamic
 explicitly out of lens context.

 I don't know how 'Member' will fit in the lens hierarchy
 http://i.imgur.com/FgfVW.png or even if it fits at all.
 Member is weaker than Getter and probably is a Fold since you have
 only partial getting (^?) for Member. Member is weaker than Prism
 since you cannot construct a whole Object from just one Member. On the
 other hand, setter side of Member requires (s - b - t) interface of
 a Lens, because the setter need to update the whole Object when the
 field under concern is missing.

 That said, let me put this question in another way;

  We can construct a (Simple Lens s a) from (getter :: s - a) and
 (setter :: s - a - s), and we can construct a (Getter s a) from
 (getter :: s - a).
   Then why we cannot construct a (Simple Setter s a) from (setter :: s
 - a - s) ? 

 Does Member deserve a new node in The Lens Hierarchy tree? Or can we
 implement it by combinations of existing prisms, folds etc? Or does it
 fall outside of the lens framework?

 I appreciate any comments.
 Takayuki

 [1] https://github.com/nushio3/practice/tree/master/duck
 [2] http://d.hatena.ne.jp/nushio/20121226#p2 (Japanese)
 [3] 
 http://hackage.haskell.org/packages/archive/dynamic-object/0.1.0.1/doc/html/Data-Object-Dynamic-Types.html
 [4] https://github.com/nushio3/practice/blob/master/lens/newfield.hs
 [5] https://github.com/nushio3/practice/blob/master/lens/object-4.hs


 --
 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] Lens, with ability to create a data-field when it's missing

2013-01-03 Thread Takayuki Muranushi
Dear All, I really am enjoying the lens (it is tough to learn, though :)

Recently, I've been trying to implement a dynamic object --- a
collection of methods that you can update at run-time --- using lens
[1][2][3]. After several attempts, I think I have located the center
of my problem:

Lens with the ability to create a data-field when it's missing. My
question: is it possible?

There are many excellent examples of partial lenses in the lens
library, such as '_head' from Data.List.Lens 'dynamic' from
Data.Dynamic.Lens . To me, they seem to share the following set of
common behavior (allow me to use inaccurate terms...)

- set l a s : if the field is present, insert 'a'; otherwise, do nothing.
- over l f s : if the field is present, map 'f' over it. otherwise, do nothing.
- preview l s : if the field is present, return 'Just a'. otherwise,
return 'Nothing' .

Instead, I want the following set of behaviors:

- set l a s : if the field is present, insert 'a'; otherwise, *create
the field* and insert 'a'.
- over l f s : if the field is present, map 'f' over it. otherwise, do nothing.
- preview l s : if the field is present, return 'Just a'. otherwise,
return 'Nothing' .

For example, the current behavior of _head is
 []  _head .~ 1
[]
I want to implement a variant _head' , such that
 []  _head' .~ 1
[1]


Let us call this behavior 'Member' for the moment.

I have a implementation of 'Member' [4][5] but they are
unsatisfactory. [4] involves runtime errors and breaking of lens laws.
[5] shows that we can create a field only if we treat Dynamic
explicitly out of lens context.

I don't know how 'Member' will fit in the lens hierarchy
http://i.imgur.com/FgfVW.png or even if it fits at all.
Member is weaker than Getter and probably is a Fold since you have
only partial getting (^?) for Member. Member is weaker than Prism
since you cannot construct a whole Object from just one Member. On the
other hand, setter side of Member requires (s - b - t) interface of
a Lens, because the setter need to update the whole Object when the
field under concern is missing.

That said, let me put this question in another way;

 We can construct a (Simple Lens s a) from (getter :: s - a) and
(setter :: s - a - s), and we can construct a (Getter s a) from
(getter :: s - a).
  Then why we cannot construct a (Simple Setter s a) from (setter :: s
- a - s) ? 

Does Member deserve a new node in The Lens Hierarchy tree? Or can we
implement it by combinations of existing prisms, folds etc? Or does it
fall outside of the lens framework?

I appreciate any comments.
Takayuki

[1] https://github.com/nushio3/practice/tree/master/duck
[2] http://d.hatena.ne.jp/nushio/20121226#p2 (Japanese)
[3] 
http://hackage.haskell.org/packages/archive/dynamic-object/0.1.0.1/doc/html/Data-Object-Dynamic-Types.html
[4] https://github.com/nushio3/practice/blob/master/lens/newfield.hs
[5] https://github.com/nushio3/practice/blob/master/lens/object-4.hs


--
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


Re: [Haskell-cafe] Variable-arity zipWith (re)invented.

2012-12-10 Thread Takayuki Muranushi
Repeated thanks to you, Adam! Your code is brilliantly simple.

Sadly, I cannot reproduce the behaviors in your comments on my ghci
(7.6.1)  .
Can we guess why? The version of packages we are using?

Mines are here.

https://github.com/nushio3/practice/tree/master/variable-arity/adam


  :t forZ [1,2,3] (+)
forZ [1,2,3] (+)
  :: (Num t, Num a, TypeCast br HFalse,
  HBuild2' br (HCons [t] HNil) (a - a - a) r) =
 r
  forZ [1,2,3] [10] (+)

interactive:13:1:
Couldn't match type `[y]' with `(a0 - a0 - a0) - t0'
When using functional dependencies to combine
  Apply ApplyZap (a, b) [y],
arising from the dependency `f a - r'
in the instance declaration at Part1.lhs:193:12
  Apply ApplyZap ([[t2]], [t1]) ((a0 - a0 - a0) - t0),
arising from a use of `forZ' at interactive:13:1-4
In the expression: forZ [1, 2, 3] [10] (+)
In an equation for `it': it = forZ [1, 2, 3] [10] (+)
 forZ [1,2,3] hi there (,)

interactive:14:1:
Couldn't match type `[y]' with `(a0 - b0 - (a0, b0)) - t0'
When using functional dependencies to combine
  Apply ApplyZap (a, b) [y],
arising from the dependency `f a - r'
in the instance declaration at Part1.lhs:193:12
  Apply ApplyZap ([[Char]], [t1]) ((a0 - b0 - (a0, b0)) - t0),
arising from a use of `forZ' at interactive:14:1-4
In the expression: forZ [1, 2, 3] hi there (,)
In an equation for `it': it = forZ [1, 2, 3] hi there (,)



Best,

Takayuki

2012/12/11 adam vogt vogt.a...@gmail.com:
 On Sat, Dec 8, 2012 at 10:27 AM, Takayuki Muranushi muranu...@gmail.com 
 wrote:
 Continued discussion from

 https://groups.google.com/d/topic/haskell-cafe/-e-xaCEbd-w/discussion
 https://groups.google.com/d/topic/haskell-cafe/kM_-NvXAcx8/discussion

 Thank you for all the answeres and thinkings;


 Here's zipWithN for general Zip functors: [1] . This, together with
 [2] may constitute a small hackage. A modification from Wren's idea to
 [1] is the use of fmap instead of repeat.

 I'm wondering if there are any laws for Zip functors. I first thought
 that there are similarity between Zips and Applicatives, as [3] states

instance Applicative f = Zip f where
zip = liftA2 (,)

 However, my intuition is that zipping two arrays should result in an
 array of size of the same order as two, giving rise to a Zip functor
 law candidate:

 zipWith const xs $ zipWith const xs ys == zipWith const xs ys

 which is violated by the above statement zip = liftA2 (,) .




 [1] 
 https://github.com/nushio3/practice/blob/master/variable-arity/ZipWithN-2.hs
 [2] https://github.com/nushio3/practice/blob/master/free-objects/zipf-12.hs
 [3] 
 http://hackage.haskell.org/packages/archive/TypeCompose/0.9.7/doc/html/Data-Zip.html

 Hi again, Takayuki

 While the forZN in zipf-12 is able to infer the result type given
 arguments, it doesn't give any useful information about types for
 arguments unlike an example here:

 http://code.haskell.org/~aavogt/flip_zipWithN/P4.hs

 which imports a slight modification of Paczesiowa's code:
 http://code.haskell.org/~aavogt/flip_zipWithN/Part1.lhs

 But maybe it isn't possible to infer much about earlier arguments
 given later ones since there is an instance   Zip ((-) a), that forZN
 apparently can work with.

 Adam



-- 
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] Variable-arity zipWith (re)invented.

2012-12-08 Thread Takayuki Muranushi
Continued discussion from

https://groups.google.com/d/topic/haskell-cafe/-e-xaCEbd-w/discussion
https://groups.google.com/d/topic/haskell-cafe/kM_-NvXAcx8/discussion

Thank you for all the answeres and thinkings;


Here's zipWithN for general Zip functors: [1] . This, together with
[2] may constitute a small hackage. A modification from Wren's idea to
[1] is the use of fmap instead of repeat.

I'm wondering if there are any laws for Zip functors. I first thought
that there are similarity between Zips and Applicatives, as [3] states

instance Applicative f = Zip f where
zip = liftA2 (,)

However, my intuition is that zipping two arrays should result in an
array of size of the same order as two, giving rise to a Zip functor
law candidate:

zipWith const xs $ zipWith const xs ys == zipWith const xs ys

which is violated by the above statement zip = liftA2 (,) .




[1] https://github.com/nushio3/practice/blob/master/variable-arity/ZipWithN-2.hs
[2] https://github.com/nushio3/practice/blob/master/free-objects/zipf-12.hs
[3] 
http://hackage.haskell.org/packages/archive/TypeCompose/0.9.7/doc/html/Data-Zip.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


Re: [Haskell-cafe] Understanding GHC's instance inference.

2012-12-07 Thread Takayuki Muranushi
Thank you, Adam,

for I didn't know about paczesiowa's article. That will be useful for me.

What I was trying to make is a zipWithN that takes the zipper function
as its last argument, not the first. This is because in my
applications the zipper functions tend to be complicated lambdas, as
illustrated in [1] . Since we live in curried world where all
functions are superficially unary, to define the last argument, and
to implement forZN, needs extra work than to implement zipWithN, I
believe [2] . I'm interested how much we can make these two share
their internal mechanisms.


[1] https://github.com/nushio3/practice/blob/master/free-objects/zipf-05.hs
[2] https://groups.google.com/forum/?fromgroups=#!topic/haskell-cafe/-e-xaCEbd-w

2012/12/6 adam vogt vogt.a...@gmail.com:
 On Wed, Dec 5, 2012 at 12:12 AM, Takayuki Muranushi muranu...@gmail.com 
 wrote:
 Dear everyone,

 I have a code
 https://github.com/nushio3/practice/blob/master/instance-inference/zipf-11-1.hs

 that produces a type-error when I remove a type signature.
 https://github.com/nushio3/practice/blob/master/instance-inference/zipf-11.hs

 Hi Takayuki,

 The ghc manual sections about the extensions are a good place to
 start. Also check out http://okmij.org/ftp/Haskell/

 I think you are expecting forZN to be able to use the number of - in
 the function(s) supplied to decide how many lists to take, as done
 here: http://paczesiowa.blogspot.ca/2010/03/generalized-zipwithn.html

 Replacing the [] container used in the above zipWithN with a
 `Data.Key.Zip v = v' that is the same for all of the arguments might
 be straightforward. But there are a lot of type signatures that have
 to add that parameter, and maybe that will interfere with the
 incoherent instance business going on.

 Adam

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



-- 
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


Re: [Haskell-cafe] Vector mysteries

2012-12-06 Thread Takayuki Muranushi
Hi, Fixie,

Sadly, I've heard that data type contexts are widely considered a
misfeature, and is going to be removed from the language. see

http://www.haskell.org/ghc/docs/7.6.1/html/users_guide/data-type-extensions.html

Moreover, when Row explicitly takes its type arguments, the use of
ScopedTypeVariables lets you do the following:

https://github.com/nushio3/practice/blob/master/show/storable-mutable-vector.hs


Best,

2012/12/3 Fixie Fixie fixie.fi...@rocketmail.com:
 Hi

 I am trying to implement Show for a storable-mutable-vector.

 Does anyone have a clue why the type-system is killing me :-)

 Code is below...

 Cheers

 Felix

 

 {-# LANGUAGE ExistentialQuantification #-}

 import Control.Monad (liftM2)
 import qualified Data.Vector.Unboxed as V
 import qualified Data.Vector.Unboxed.Mutable as MV
 import Data.Vector.Storable.Mutable
 import GHC.Prim (RealWorld)
 import Control.Monad.Primitive
 import Control.Monad
 import qualified Data.Vector as VEC
 import qualified Data.Vector.Generic.Mutable as GM
 import Data.Int
 import Data.Typeable.Internal
 import Data.Primitive

 data Row = forall m s. (Storable s, MV.Unbox s, Prim s, PrimMonad m) = Row
 (MV.MVector (PrimState m) s)

 instance Show Row where
 show (Row row) = do
 let xx = MV.read row 0
 Done

 main :: IO ()
 main = do
 print Done

 I get this error:

 Could not deduce (PrimState m ~ PrimState m0)
 from the context (Storable s, MV.Unbox s, Prim s, PrimMonad m)
   bound by a pattern with constructor
  Row :: forall (m :: * - *) s.
 (Storable s, MV.Unbox s, Prim s, PrimMonad m) =
 MV.MVector (PrimState m) s - Row,
in an equation for `show'
 NB: `PrimState' is a type function, and may not be injective
 Expected type: MV.MVector (PrimState m0) s
   Actual type: MV.MVector (PrimState m) s
 In the first argument of `MV.read', namely `row'
 In the expression: MV.read row 0


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




-- 
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


Re: [Haskell-cafe] computation over containers, greatly simplified notation.

2012-12-01 Thread Takayuki Muranushi
Thank you Jason, I have implemented those.
https://github.com/nushio3/practice/blob/master/free-objects/zipn-03.hs

I implemented what I have wanted. It is forZN in the following code.

https://github.com/nushio3/practice/blob/master/free-objects/zipf-05.hs

forZN, much like printf, can be used in place of any of the following
functions.

forLiftZ1 :: Zip f = f a - (a - b) - f bforLiftZ2 :: Zip f = f a
- f b - (a - b - c) - f c
forLiftZ3 :: Zip f = f a - f b - f c - (a - b - c - d) - f d

...and more...


The last example in above code is the usecase of forZN in my mind: to zip
several arrays with a long lambda. This pattern occurs frequently in my
codes.

One drawback of current approach is that we need verbose type annotations
like
 :: V.Vector String in   print $ (forZN vd1 vc1 vi1 f_dci_s :: V.Vector
String) .

Maybe this is because PType carries insufficient type-level information,
compared to Reduce and Insert. Now I'm now wondering if we can use
ghc-7.6.1's rich kind features such as type-level lists to remove those
verbose type annotations.




2012/12/1 Jason Dagit dag...@gmail.com

 You might find this paper an interesting read:
 http://www.brics.dk/RS/01/10/

 On Fri, Nov 30, 2012 at 4:43 PM, Takayuki Muranushi 
 muranu...@gmail.comwrote:

 Dear everyone,

 After a number of attempts [1] I'm starting to think that my initial
 approach was ill-directed.

 After all, Functor, Applicative, Zip are three different classes.
 Functors are type constructors where you can map unary functions over
 them.
 Applicatives are those with map-over of zero-ary functions (pure,) unary
 functions, binary functions, ternary functions, ... etc.
 Zip are those with unary, binary, ternary ... mapover, but not zero-ary
 map-over.

 Repa Arrays and Vectors belong to Zip because there's no trivial unique
 way to implement pure.

 What the customer really needed [2] seems to be the following series of
 functions:


 forLiftZ1 :: Zip f = f a - (a - b) - f b



 forLiftZ2 :: Zip f = f a - f b - (a - b - c) - f c




 forLiftZ3 :: Zip f = f a - f b - f c - (a - b - c - d) - f d



 Now I'm trying if it's possible to implement the series in a single shot
 [3] .

 I'm reporting my progress for anyone who might be still thinking for me.
 Thank you!!

 [1] https://github.com/nushio3/practice/tree/master/free-objects
 [2] http://www.projectcartoon.com/cartoon/3
 [3]
 https://github.com/nushio3/practice/blob/master/free-objects/printf6.hs




 2012/11/29 Takayuki Muranushi muranu...@gmail.com

 Dear all,

 I came up with an idea to greatly simplify some kinds of array
 computations. It should work well with many kinds of arrays. Is this new?

 https://gist.github.com/4162375



 These few days, I've been trying to rewrite a hydrodynamic simulation
 code that used Data.Vector (~250 lines), to Repa [1] . It seemed promising,
 but soon I realized that I needed to use Repa.map and Repa.zipWith almost
 everywhere. I need careful thinking to transform every lines (that used
 vector's indexing) to Repa's point-free stile. Is there any better ways?

 Then I realized that I was the author of Paraiso [2], a DSL for stencil
 computation. One of its feature is to write down array computation just as
 if it were scalar computation.

 Basically what I need is ZipList-like Applicative instances for vectors
 and Repa arrays. Why not they support ZipVector? Because 'pure' of zipList
 was an infinite list and you can't do infinite vectors. Then I came up with
 this idea.

 https://gist.github.com/4162375

 the wrapper W does several things: it represents the 'pure,' homogeneous
 array in a space-efficient manner, and also serves as a newtype-wrapper of
 Num (and possibly Fractional, Floating...) instances.

 Questions are: is this technology new? or promising? doomed?
 It seems to me like a free-Applicative, like the free-Monad theory. Are
 they related?
 The function 'backend' helps to mix in the non-zip-like computations.
 How can we remove the 'undefined' in the 'backend?'
 Some of Repa computations are Monads. W needs to be a monad transformer
 to incooperate this.

 Also I'm grateful to past cafe discussion on existing Zippable
 implementations [3][4] .

 [1] hackage.haskell.org/package/repa
 [2] http://hackage.haskell.org/package/Paraiso
 [3] http://www.haskell.org/pipermail/haskell-cafe/2009-July/064403.html
 [4]
 http://hackage.haskell.org/packages/archive/category-extras/latest/doc/html/Control-Functor-Zip.html


 --
 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





-- 
Takayuki MURANUSHI
The Hakubi Center for Advanced Research, Kyoto University

Re: [Haskell-cafe] computation over containers, greatly simplified notation.

2012-12-01 Thread Takayuki Muranushi
Dear all,

https://github.com/nushio3/practice/blob/master/free-objects/zipf-12.hs

I was finally able to remove the verbose type annotations.

The point was (1) to let the argument-list carry the type-constructor
information, so that only values of the type (v a) can enter the
heterogeneous list;

data Cons (v :: * - *) a b = Cons a b deriving (Eq, Show)
data Nil  (v :: * - *) = Nil  deriving (Eq, Show)

(2) to change the remainder of the program accordingly, and (3) to add
the following subtle modification, because instance finder does not
attempt to match unknown type a0 to v result, but it does so to
result.


class Reduce v f vxS result vyS | v f vxS - result vyS where
  reduce :: v f - vxS - (v result, vyS)
   ↓
class Reduce v f vxS result vyS | v f vxS - result vyS where
  reduce :: v f - vxS - (result, vyS)


Other samples work with modest type annotations.
https://github.com/nushio3/practice/blob/master/free-objects/zipf-13.hs


2012/12/1 Takayuki Muranushi muranu...@gmail.com

 Thank you Jason, I have implemented those. 
 https://github.com/nushio3/practice/blob/master/free-objects/zipn-03.hs

 I implemented what I have wanted. It is forZN in the following code.

 https://github.com/nushio3/practice/blob/master/free-objects/zipf-05.hs

 forZN, much like printf, can be used in place of any of the following 
 functions.

 forLiftZ1 :: Zip f = f a - (a - b) - f b
 forLiftZ2 :: Zip f = f a - f b - (a - b - c) - f c
 forLiftZ3 :: Zip f = f a - f b - f c - (a - b - c - d) - f
 d

 ...and more...


 The last example in above code is the usecase of forZN in my mind: to zip 
 several arrays with a long lambda. This pattern occurs frequently in my codes.

 One drawback of current approach is that we need verbose type annotations like
  :: V.Vector String in   print $ (forZN vd1 vc1 vi1 f_dci_s :: V.Vector 
 String) .

 Maybe this is because PType carries insufficient type-level information, 
 compared to Reduce and Insert. Now I'm now wondering if we can use 
 ghc-7.6.1's rich kind features such as type-level lists to remove those 
 verbose type annotations.





 2012/12/1 Jason Dagit dag...@gmail.com

 You might find this paper an interesting read: http://www.brics.dk/RS/01/10/

 On Fri, Nov 30, 2012 at 4:43 PM, Takayuki Muranushi muranu...@gmail.com 
 wrote:

 Dear everyone,

 After a number of attempts [1] I'm starting to think that my initial 
 approach was ill-directed.

 After all, Functor, Applicative, Zip are three different classes.
 Functors are type constructors where you can map unary functions over them.
 Applicatives are those with map-over of zero-ary functions (pure,) unary 
 functions, binary functions, ternary functions, ... etc.
 Zip are those with unary, binary, ternary ... mapover, but not zero-ary 
 map-over.

 Repa Arrays and Vectors belong to Zip because there's no trivial unique way 
 to implement pure.

 What the customer really needed [2] seems to be the following series of 
 functions:


 forLiftZ1 :: Zip f = f a - (a - b) - f b




 forLiftZ2 :: Zip f = f a - f b - (a - b - c) - f c





 forLiftZ3 :: Zip f = f a - f b - f c - (a - b - c - d) - f d





 Now I'm trying if it's possible to implement the series in a single shot 
 [3] .

 I'm reporting my progress for anyone who might be still thinking for me. 
 Thank you!!

 [1] https://github.com/nushio3/practice/tree/master/free-objects
 [2] http://www.projectcartoon.com/cartoon/3
 [3] https://github.com/nushio3/practice/blob/master/free-objects/printf6.hs




 2012/11/29 Takayuki Muranushi muranu...@gmail.com

 Dear all,

 I came up with an idea to greatly simplify some kinds of array 
 computations. It should work well with many kinds of arrays. Is this new?

 https://gist.github.com/4162375



 These few days, I've been trying to rewrite a hydrodynamic simulation code 
 that used Data.Vector (~250 lines), to Repa [1] . It seemed promising, but 
 soon I realized that I needed to use Repa.map and Repa.zipWith almost 
 everywhere. I need careful thinking to transform every lines (that used 
 vector's indexing) to Repa's point-free stile. Is there any better ways?

 Then I realized that I was the author of Paraiso [2], a DSL for stencil 
 computation. One of its feature is to write down array computation just as 
 if it were scalar computation.

 Basically what I need is ZipList-like Applicative instances for vectors 
 and Repa arrays. Why not they support ZipVector? Because 'pure' of zipList 
 was an infinite list and you can't do infinite vectors. Then I came up 
 with this idea.

 https://gist.github.com/4162375

 the wrapper W does several things: it represents the 'pure,' homogeneous 
 array in a space-efficient manner, and also serves as a newtype-wrapper of 
 Num (and possibly Fractional, Floating...) instances.

 Questions are: is this technology new? or promising? doomed?
 It seems to me like a free-Applicative, like the free-Monad theory. Are 
 they related?
 The function 'backend' helps to mix in the non-zip

Re: [Haskell-cafe] computation over containers, greatly simplified notation.

2012-11-30 Thread Takayuki Muranushi
Dear everyone,

After a number of attempts [1] I'm starting to think that my initial
approach was ill-directed.

After all, Functor, Applicative, Zip are three different classes.
Functors are type constructors where you can map unary functions over them.
Applicatives are those with map-over of zero-ary functions (pure,) unary
functions, binary functions, ternary functions, ... etc.
Zip are those with unary, binary, ternary ... mapover, but not zero-ary
map-over.

Repa Arrays and Vectors belong to Zip because there's no trivial unique way
to implement pure.

What the customer really needed [2] seems to be the following series of
functions:

forLiftZ1 :: Zip f = f a - (a - b) - f b
forLiftZ2 :: Zip f = f a - f b - (a - b - c) - f c

forLiftZ3 :: Zip f = f a - f b - f c - (a - b - c - d) - f d

Now I'm trying if it's possible to implement the series in a single shot
[3] .

I'm reporting my progress for anyone who might be still thinking for me.
Thank you!!

[1] https://github.com/nushio3/practice/tree/master/free-objects
[2] http://www.projectcartoon.com/cartoon/3
[3] https://github.com/nushio3/practice/blob/master/free-objects/printf6.hs



2012/11/29 Takayuki Muranushi muranu...@gmail.com

 Dear all,

 I came up with an idea to greatly simplify some kinds of array
 computations. It should work well with many kinds of arrays. Is this new?

 https://gist.github.com/4162375



 These few days, I've been trying to rewrite a hydrodynamic simulation code
 that used Data.Vector (~250 lines), to Repa [1] . It seemed promising, but
 soon I realized that I needed to use Repa.map and Repa.zipWith almost
 everywhere. I need careful thinking to transform every lines (that used
 vector's indexing) to Repa's point-free stile. Is there any better ways?

 Then I realized that I was the author of Paraiso [2], a DSL for stencil
 computation. One of its feature is to write down array computation just as
 if it were scalar computation.

 Basically what I need is ZipList-like Applicative instances for vectors
 and Repa arrays. Why not they support ZipVector? Because 'pure' of zipList
 was an infinite list and you can't do infinite vectors. Then I came up with
 this idea.

 https://gist.github.com/4162375

 the wrapper W does several things: it represents the 'pure,' homogeneous
 array in a space-efficient manner, and also serves as a newtype-wrapper of
 Num (and possibly Fractional, Floating...) instances.

 Questions are: is this technology new? or promising? doomed?
 It seems to me like a free-Applicative, like the free-Monad theory. Are
 they related?
 The function 'backend' helps to mix in the non-zip-like computations. How
 can we remove the 'undefined' in the 'backend?'
 Some of Repa computations are Monads. W needs to be a monad transformer to
 incooperate this.

 Also I'm grateful to past cafe discussion on existing Zippable
 implementations [3][4] .

 [1] hackage.haskell.org/package/repa
 [2] http://hackage.haskell.org/package/Paraiso
 [3] http://www.haskell.org/pipermail/haskell-cafe/2009-July/064403.html
 [4]
 http://hackage.haskell.org/packages/archive/category-extras/latest/doc/html/Control-Functor-Zip.html


 --
 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


Re: [Haskell-cafe] Equality test between types that returns type-level Bool ?

2012-11-28 Thread Takayuki Muranushi
By tracing how unittyped produced the 'True-s and 'False-s in the error
messages, and by Oleg's lecture,

 1 meter + 5 second

interactive:17:9:
Couldn't match type 'False with 'True
When using functional dependencies to combine
  UnitTyped.And 'False 'False 'False,
arising from the dependency `a b - c'
in the instance declaration in `UnitTyped'
  UnitTyped.And 'False 'False 'True,
arising from a use of `+' at interactive:17:9
In the expression: 1 meter + 5 second
In an equation for `it': it = 1 meter + 5 second


I understood how type-level equalities
https://github.com/nushio3/dimensional-tf/blob/master/attic/typeeq-01.hs
and type-level list lookups
https://github.com/nushio3/dimensional-tf/blob/master/attic/typeeq-03.hs

can be implemented using overlapped instances. Thank you for the
instructions.

and I'm looking forward to see TYPEREP with ghc7.6.1's promoted integers
and TH pretty soon!


2012/11/27 Takayuki Muranushi muranu...@gmail.com

 Dear Gábor, Erik, and Oleg,

 Thank you for your advices. Also what I have wanted, the extensible
 dimensional type system, has just been released.

 http://hackage.haskell.org/package/unittyped-0.1

 Now I have homeworks to test these, thank you!




 2012/11/27 Erik Hesselink hessel...@gmail.com

 If you're up for it, Oleg has a lot of interesting material about this
 subject [1].

 Regards,

 Erik

 [1] http://okmij.org/ftp/Haskell/typeEQ.html


 On Sun, Nov 25, 2012 at 9:36 AM, Takayuki Muranushi 
 muranu...@gmail.comwrote:

 Is it possible to write

 type family SameType a b :: Bool

 which returns True if a and b are the same type, and False otherwise?

 I encountered this problem when I was practicing promoted lists and
 tuples in ghc-7.6.1. One of my goal for practice is to write more
 modular version of extensible-dimensional calculations, and to
 understand whether ghc-7.6.1 is capable of it.


 http://hackage.haskell.org/packages/archive/dimensional/0.10.2/doc/html/Numeric-Units-Dimensional-Extensible.html

 Some of my attempts:

 https://github.com/nushio3/dimensional-tf/blob/master/attic/list-02.hs
 This fails because :==: is not an equality test between a and b, but
 is a equality test within a (promoted) kind.

 https://github.com/nushio3/dimensional-tf/blob/master/attic/list-03.hs
 This fails because type instance declarations are not read from top to
 bottom. (not like function declarations.)

 https://github.com/nushio3/dimensional-tf/blob/master/attic/map-03.hs
 I could define a lookup using class constraints, but when I use it,
 results in overlapping instances.

 So, will somebody teach me which of the following is correct?

 * We can write a type family SameType a b :: Bool
 * We cannot do that because of theoretical reason (that leads to
 non-termination etc.)
 * We cannot write SameType, but there are ways to write functions like
 'filter' and 'merge' , over type-level lists, without using SameType.

 Always grateful to your help,
 --
 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





 --
 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] computation over containers, greatly simplified notation.

2012-11-28 Thread Takayuki Muranushi
Dear all,

I came up with an idea to greatly simplify some kinds of array
computations. It should work well with many kinds of arrays. Is this new?

https://gist.github.com/4162375



These few days, I've been trying to rewrite a hydrodynamic simulation code
that used Data.Vector (~250 lines), to Repa [1] . It seemed promising, but
soon I realized that I needed to use Repa.map and Repa.zipWith almost
everywhere. I need careful thinking to transform every lines (that used
vector's indexing) to Repa's point-free stile. Is there any better ways?

Then I realized that I was the author of Paraiso [2], a DSL for stencil
computation. One of its feature is to write down array computation just as
if it were scalar computation.

Basically what I need is ZipList-like Applicative instances for vectors and
Repa arrays. Why not they support ZipVector? Because 'pure' of zipList was
an infinite list and you can't do infinite vectors. Then I came up with
this idea.

https://gist.github.com/4162375

the wrapper W does several things: it represents the 'pure,' homogeneous
array in a space-efficient manner, and also serves as a newtype-wrapper of
Num (and possibly Fractional, Floating...) instances.

Questions are: is this technology new? or promising? doomed?
It seems to me like a free-Applicative, like the free-Monad theory. Are
they related?
The function 'backend' helps to mix in the non-zip-like computations. How
can we remove the 'undefined' in the 'backend?'
Some of Repa computations are Monads. W needs to be a monad transformer to
incooperate this.

Also I'm grateful to past cafe discussion on existing Zippable
implementations [3][4] .

[1] hackage.haskell.org/package/repa
[2] http://hackage.haskell.org/package/Paraiso
[3] http://www.haskell.org/pipermail/haskell-cafe/2009-July/064403.html
[4]
http://hackage.haskell.org/packages/archive/category-extras/latest/doc/html/Control-Functor-Zip.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


Re: [Haskell-cafe] Equality test between types that returns type-level Bool ?

2012-11-26 Thread Takayuki Muranushi
Dear Gábor, Erik, and Oleg,

Thank you for your advices. Also what I have wanted, the extensible
dimensional type system, has just been released.

http://hackage.haskell.org/package/unittyped-0.1

Now I have homeworks to test these, thank you!



2012/11/27 Erik Hesselink hessel...@gmail.com

 If you're up for it, Oleg has a lot of interesting material about this
 subject [1].

 Regards,

 Erik

 [1] http://okmij.org/ftp/Haskell/typeEQ.html


 On Sun, Nov 25, 2012 at 9:36 AM, Takayuki Muranushi 
 muranu...@gmail.comwrote:

 Is it possible to write

 type family SameType a b :: Bool

 which returns True if a and b are the same type, and False otherwise?

 I encountered this problem when I was practicing promoted lists and
 tuples in ghc-7.6.1. One of my goal for practice is to write more
 modular version of extensible-dimensional calculations, and to
 understand whether ghc-7.6.1 is capable of it.


 http://hackage.haskell.org/packages/archive/dimensional/0.10.2/doc/html/Numeric-Units-Dimensional-Extensible.html

 Some of my attempts:

 https://github.com/nushio3/dimensional-tf/blob/master/attic/list-02.hs
 This fails because :==: is not an equality test between a and b, but
 is a equality test within a (promoted) kind.

 https://github.com/nushio3/dimensional-tf/blob/master/attic/list-03.hs
 This fails because type instance declarations are not read from top to
 bottom. (not like function declarations.)

 https://github.com/nushio3/dimensional-tf/blob/master/attic/map-03.hs
 I could define a lookup using class constraints, but when I use it,
 results in overlapping instances.

 So, will somebody teach me which of the following is correct?

 * We can write a type family SameType a b :: Bool
 * We cannot do that because of theoretical reason (that leads to
 non-termination etc.)
 * We cannot write SameType, but there are ways to write functions like
 'filter' and 'merge' , over type-level lists, without using SameType.

 Always grateful to your help,
 --
 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





-- 
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] Equality test between types that returns type-level Bool ?

2012-11-25 Thread Takayuki Muranushi
Is it possible to write

type family SameType a b :: Bool

which returns True if a and b are the same type, and False otherwise?

I encountered this problem when I was practicing promoted lists and
tuples in ghc-7.6.1. One of my goal for practice is to write more
modular version of extensible-dimensional calculations, and to
understand whether ghc-7.6.1 is capable of it.

http://hackage.haskell.org/packages/archive/dimensional/0.10.2/doc/html/Numeric-Units-Dimensional-Extensible.html

Some of my attempts:

https://github.com/nushio3/dimensional-tf/blob/master/attic/list-02.hs
This fails because :==: is not an equality test between a and b, but
is a equality test within a (promoted) kind.

https://github.com/nushio3/dimensional-tf/blob/master/attic/list-03.hs
This fails because type instance declarations are not read from top to
bottom. (not like function declarations.)

https://github.com/nushio3/dimensional-tf/blob/master/attic/map-03.hs
I could define a lookup using class constraints, but when I use it,
results in overlapping instances.

So, will somebody teach me which of the following is correct?

* We can write a type family SameType a b :: Bool
* We cannot do that because of theoretical reason (that leads to
non-termination etc.)
* We cannot write SameType, but there are ways to write functions like
'filter' and 'merge' , over type-level lists, without using SameType.

Always grateful to your help,
--
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] [solved] forall disappear from type signature

2012-11-02 Thread Takayuki Muranushi
Today, I encountered a strange trouble with higher-rank polymorphism. It
was finally solved by nominal typing. Was it a bug in type checker? lack of
power in type inference? or lack of my understanding? I'll submit this in
hope that it will at least result in better GHC error message some day:

My following code

https://github.com/sugoi/sugoi/blob/0aec19b29274ddb7c5ae46b9b733e91bae0790b2/Sugoi/Types.hs

 runDB :: Lens NetworkState RIB
 runDB = lens (f::NetworkState - RIB) (\x s - s { _runDB = x })
  where f :: NetworkState - RIB

Didn't typecheck with following error:

Sugoi/Types.hs:38:15:
Couldn't match expected type `RIB'
with actual type `DB.DBMT (Maybe Int) IO a0
  - IO (StM (DB.DBMT (Maybe Int) IO) a0)'
Expected type: NetworkState - RIB
  Actual type: NetworkState
   - DB.DBMT (Maybe Int) IO a0
   - IO (StM (DB.DBMT (Maybe Int) IO) a0)
In the first argument of `lens', namely
  `(f :: NetworkState - RIB)'
In the expression:
  lens (f :: NetworkState - RIB) (\ x s - s {_runDB = x})


How come an expression `(f :: NetworkState - RIB)' is not of type
NetworkState - RIB ?
When I changed the definition of runDB as follows,

 runDB = lens (\NetworkState{_runDB = x} - x) (\x s - s { _runDB = x })

The source of error was more clear:

Expected type: DB.DBMT (Maybe Int) IO a1
   - IO (StM (DB.DBMT (Maybe Int) IO) a1)
  Actual type: DB.DBMT (Maybe Int) IO a
   - IO (StM (DB.DBMT (Maybe Int) IO) a)

So, ghc couldn't unify these two types. By using the nominal typing, namely

 - type RIB = RunInBase (DB.DBMT (Maybe Int) IO) IO
 + newtype RIB = RIB (RunInBase (DB.DBMT (Maybe Int) IO) IO)

the problem was solved.

Always grateful to haskell-cafe from being there,
-- 
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] ANNOUNCE: cmaes, a generic optimizer

2012-10-02 Thread Takayuki Muranushi
Hello,

I'm pleased to announce cmaes
http://hackage.haskell.org/package/cmaes , a library for optimization
(in mathematical sense). That is, given a function f :: a-Double, to
find x of type a so that (f x) is as small as possible.

CMA-ES is an optimization algorithm developed by Nikolaus Hansen and
his folks http://www.lri.fr/~hansen/cmaesintro.html . It is a
stochastic approach, it does not require gradient information. These
properties makes it robust against noise and makes it widely
applicable.

The cmaes packages is a Haskell wrapper to their elaborate Python
code. The robustness of CMA-ES and generic programming put together,
you can now describe optimization problems for various types of
functions just in one line. CMA-ES is not a silver bullet, of course,
but it's been working fine for many application including mine, and I
hope this library will drastically reduce the initial cost of trying
one for you.

Type will tell what cmaes can do. Please refer to the running document
http://hackage.haskell.org/packages/archive/cmaes/0.2.1/doc/html/Numeric-Optimization-Algorithms-CMAES.html
.

You can optimize functions of type ([Double]- Double) and ([Double]-
IO Double) , that's usual. Next up, you can optimize (Traversable t =
t Double- Double) and (Traversable t = t Double- IO Double) where
you are pretty sure about which parameter you're tuning. Finally, you
can do (Data a = a - Double) and (Data a = a - IO Double) , where
SYB will find the hidden Doubles to be optimized over for you. It was
my joy to see optimization of function of type such as (Triangle -
Double) works out of the box.

Any comments, suggestions, bug reports are welcome!

Thanks,
-- 
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


Re: [Haskell-cafe] An easy way to represent and modify graphs?

2012-09-21 Thread Takayuki Muranushi
Yes Pointers. I've forgotten that. I have once dealt with structures,
with lots of IORefs.  It was smooth and fast. Thank you for reminding
me!

On the other hand, use of pointers means that our values are not
algebraic data type any more. We have to derive operations such as
map, fold, serialize by ourselves. I can do that, but am I right? Or
is there some systematic way to derive such operations?

Best regards,

Takayuki

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


Re: [Haskell-cafe] Benchmark of DFT libraries in Haskell

2012-08-06 Thread Takayuki Muranushi
Dear Ertugrul, Scott and Erik, thank you for your comments.

w.r.t the lazyness, I make the solvers to calculate the amplitude of
final FFT results (i.e. to calculate the square magnitude of array
elements and sum over them,) compare the response with the expected
results and cause side effects depending on the test result. This
should cause the FFT chain to be fully evaluated.

 * vector-fftw with wisdom was more than 1/2 times faster than fftw in
 C with wisdom (and with communication overhead.)

 I would be suspicious of that result. Calling a C function from a library
 should be slower from Haskell than from C.

Sorry for the confusion, What I meant is that vector-fftw version takes
more time than C version, but less than twice. Please compare the two lines

* fft/cpp 1 1048576 102
* fft/vector-fftw 0 1048576 102

in http://paraiso-lang.org/html/bench-dft-in-haskell.html .

P.S. including GPU contestants would be interesting!

2012/8/6 Erik de Castro Lopo mle...@mega-nerd.com:
 Takayuki Muranushi wrote:

 * vector-fftw with wisdom was more than 1/2 times faster than fftw in
 C with wisdom (and with communication overhead.)

 I would be suspicious of that result. Calling a C function from a library
 should be slower from Haskell than from C.

 Erik
 --
 --
 Erik de Castro Lopo
 http://www.mega-nerd.com/

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


Best,

-- 
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] Benchmark of DFT libraries in Haskell

2012-08-05 Thread Takayuki Muranushi
Dear everyone, I'm always grateful to your help.

I have been assigned a complicated and growing task in which I'll
perform a lot of discrete Fourier transforms, so I have measured
performance of several DFT libraries in Haskell:
http://en.pk.paraiso-lang.org/Hackage/what-is-the-fastest-dft-in-haskell/main

The raw result: http://paraiso-lang.org/html/bench-dft-in-haskell.html

I'll share the result in hope that some of you will also find this
result useful. Also, please let me know any possible flaws or
improvements in the benchmark process!

My observations are as follows:

* vector-fftw with wisdom was more than 1/2 times faster than fftw in
C with wisdom (and with communication overhead.)
* vector-fftw without wisdom was significantly _faster_ than fftw in C
without wisdom. I wonder why.
* vector-fftw over vector was faster than fft over CArray.
* any library that doesn't use fftw is much slower than those that does.

Best,
-- 
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


Re: [Haskell-cafe] Monads with The contexts?

2012-07-21 Thread Takayuki Muranushi
Dear Oleg,

You're right. The points boil down to
 That assumption (that the deviations are small) is not stated in types and it 
 is hard to see how can we enforce it.
and even if it's small, there's corner cases at df/dx = 0 or df/dx =
infinity (as you have mentioned.)

Thanks to your advices, I'll look for other ways to set up
probabilistic computations.

2012/7/19  o...@okmij.org:

 http://en.pk.paraiso-lang.org/Haskell/Monad-Gaussian
 What do you think? Will this be a good approach or bad?

 I don't think it is a Monad (or even restricted monad, see
 below). Suppose G a is a `Gaussian' monad and n :: G Double is a
 random number with the Gaussian (Normal distribution).  Then
 (\x - x * x) `fmap` n
 is a random number with the chi-square distribution (of
 the degree of freedom 1). Chi-square is _not_ a normal
 distribution. Perhaps a different example is clearer:

 (\x - if x  0 then 1.0 else 0.0) `fmap` n

 has also the type G Double but obviously does not have the normal
 distribution (since that random variable is discrete).

 There are other problems

 Let's start with some limitation; we restrict ourselves to Gaussian
 distributions and assume that the standard deviations are small
 compared to the scales we deal with.

 That assumption is not stated in types and it is hard to see how can
 we enforce it. Nothing prevents us from writing
 liftM2 n n
 in which case the variance will no longer be small compared with the
 mean.

 Just a technical remark: The way G a is written, it is a so-called
 restricted monad, which is not a monad (the adjective `restricted' is
 restrictive here).
 http://okmij.org/ftp/Haskell/types.html#restricted-datatypes





-- 
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


Re: [Haskell-cafe] Monads with The contexts?

2012-07-18 Thread Takayuki Muranushi
Done with some exercises on Gaussian distribution as a monad!

http://en.pk.paraiso-lang.org/Haskell/Monad-Gaussian
What do you think? Will this be a good approach or bad?

Also this is the first page in my attempt to create runnable, and even
testable wiki pages. To run the tests, please use
hackage.haskell.org/package/doctest .

2012/7/18 Takayuki Muranushi muranu...@gmail.com:
 Thank you Oleg, for your detailed instructions!

 First, let me clarify my problem here (in sacrifice of physical accuracy.)
 c.f. Wrong.hs .

 earthMass, sunMass, marsMass :: [Double]
 earthMass = [1,10,100]
 sunMass = (*) $  [9,10,11] * earthMass
 marsMass = (*) $ [0.09,0.1,0.11] * earthMass

 sunPerMars = (/) $ sunMass * marsMass
 sunPerMars_range = (minimum sunPerMars, maximum sunPerMars)

 sunPerMars_range
 gives (0.8181818181818182,1.2223)

 These extreme answers close to 1 or 1 are inconsistent in sense
 that they used different Earth mass value for calculating Sun and Mars
 mass. Factoring out Earth mass is perfect and efficient solution in
 this case, but is not always viable when more complicated functions
 are involved.

  We want to remove such inconsistency.

 -- Exercise: why do we need the seemingly redundant EarthMass
 -- and deriving Typeable?
 -- Could we use TemplateHaskell instead?

 Aha! you use the Types as unique keys that resides in The context.
 Smart! To  understand  this,  I have made MassStr.hs, which
 essentially does the same  thing with more familiar type Strings. Of
 course using Strings are naive and collision-prone approach. Printing
 `stateAfter` shows pretty much what have happened.

 I'll remember that we can use Types as  global identifiers.

 -- The following is essentially Control.Monad.Sharing.Memoization
 -- with one important addition
 -- Can you spot the important addition?

 type NonDet a = StateT FirstClassStore [] a
 data Key = KeyDyn Int | KeySta TypeRep
  deriving (Show, Ord, Eq)


 Hmm, I  don't see what Control.Monad.Sharing.Memoization is;  googling
 https://www.google.co.jp/search?q=Control.Monad.Sharing.Memoization
 gives our conversation at the top.

 If it's Memo in chapter 4.2 of your JFP paper, the difference I see is
 that you used Data.Set here instead of list of pairs for better
 efficiency.


 Exercise: how does the approach in the code relate to the approaches
 to sharing explained in
 http://okmij.org/ftp/tagless-final/sharing/sharing.html

 Chapter 3 introduces an  implicit impure counter, and Chapter 4 uses a
 database that is passed around.
 let_ in Chapter 5 of sharing.pdf realizes the sharing with sort of
 continuation-passing style.The unsafe counter works across the module
 (c.f. counter.zip) but is generally unpredictable...


 Now I'm on to the next task; how we represent continuous probability
 distributions? The existing libraries:

 http://hackage.haskell.org/package/probability-0.2.4
 http://hackage.haskell.org/package/ProbabilityMonads-0.1.0

 Seemingly have restricted themselves to discrete distributions, or at
 least providing Random support for Monte-Carlo simulations. There's
 some hope; I guess Gaussian distributions form a Monad provided that
 1. the standard deviations you are dealing with are small compared to
 the scale you deal with, and 2. the monadic functions are
 differentiable.

 Maybe I can use non-standard analysis and automatic differentiation;
 maybe I can resort to numerical differentiation; maybe I just give up
 and be satisfied with random sampling. I have to try first; then
 finally we can abstract upon different approaches.

 Also, I can start writing my Knowledge libraries from the part our
 knowledge is so accurate enough that the deviations are negligible
 (such as Earth mass!)


 P.S. extra  spaces may have annoyed you. I'm sorry for that. My
 keyboard is chattering badly now; I have to update him soon.


 Best wishes,

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


Re: [Haskell-cafe] Monads with The contexts?

2012-07-13 Thread Takayuki Muranushi
Thank you Tillman, and Oleg, for your advices! Since ICFP contest is
starting in a few hours, I will make a quick response with
gratefulness and will read the full paper later

Let me guess a few things, please tell me am I right.

The share :: m a - m (m a) is almost the thing I am looking for. I
have independently (believe me!) invented an equivalent, bind trick,
for my DSL:
http://nushisblogger.blogspot.jp/2012/06/builder-monad.html
but am now enlighted with what it really meant. Still, `share` cannot
bring the shared binding to global scope (e.g. it doesn't allow place
sunMass, earthMass, marsMass in separate modules)

I guess, my original question is ill-posed, since all the values in
Haskell are pure, so in the following trivial example

 earthCopyMass = earthMass

there is no way to distinguish two masses, thus there's no telling if
Earth and EarthCopy is two reference to one planet or two distinct
planets.

I don't know if memo can solve this problem. I have to test. I'll try
implement `memo` in your JFP paper section 4.2 Memoization; seems like
it's not in explicit-sharing hackage.

I'm vaguely foreseeing, that like in memoized (f2 0, f2 1, f2 0, f2 1)
we need to pass around some `world` among it. That will be random
generator seeds if our continuous-nondeterminism is an MonadIO when we
perform Monte-Carlo simulations; or it's a virtual `world` if we make
Gaussian approximation of probabilistic density functions.

To Ben: Thank you for your comments anyway! But since I'm not going to
use the List monad (the use of List was just for explanation,) the
discreteness is not an issue here. That's my intent when I said
another story. Sorry for confusion!

All the best,

Takayuki

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


[Haskell-cafe] haskell.org is so fragile

2012-07-12 Thread Takayuki Muranushi
Today I have observed that hackage.haskell.org/ timeout twice (in the
noon and in the evening.)

What is the problem? Is it that haskell users have increased so that
haskell.org is overloaded? That's very good news.
I am eager to donate some money if it requires server reinforcement.

Sincerely,
-- 
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] Monads with The contexts?

2012-07-12 Thread Takayuki Muranushi
tl;dr: Is there any way to pass the Supercombinator level names (the
names in haskell source codes with  zero indent) as context to a Monad
so that it will read from The context?

Hello, everyone. I'm thinking of representing our knowledge about our
life, the universe and everything as Haskell values. I'd also like to
address the uncertainties in our knowledge. The uncertainties are
usually continuous (probabilistic distributions) but that's another
story. Please forget about it for a while.

We learned that List is for nondeterministic context.

 earthMass, sunMass, marsMass :: [Double]

Let's pretend that there are large uncertainty in our knowledge of the
Earth mass.

 earthMass = [5.96e24, 5.97e24, 5.98e24]

Let's also pretend that we can measure the other bodys' masses only by
their ratio to the earth mass, and the measurements have large uncertainties.

 sunMass = (*) $  [2.5e5, 3e5, 4e5] * earthMass
 marsMass = (*) $ [0.01, 0.1, 1.0] * earthMass

Then, how many Mars mass object can we create by taking the sun apart?

 sunPerMars :: [Double]
 sunPerMars = (/) $ sunMass * marsMass

Sadly, this gives too many answers, and some of them are wrong because
they assume different Earth mass in calculating Sun and Mars masses,
which led to inconsistent calculation.
*Main length $ sunPerMars
81


We had to do this way;

 sunMass' e = map (e*)  [2.5e5, 3e5, 4e5]
 marsMass' e = map (e*) [0.01, 0.1, 1.0]

 sunPerMars' :: [Double]
 sunPerMars' = do
   e - earthMass
   (/) $ sunMass' e * marsMass' e

to have correct candidates (with duplicates.)

*Main length $ sunPerMars'
27

The use of (e - earthMass) seems inevitable for representing that the
two Earth masses are taken from the same source of nondeterminism.
However, as the chain of the reasoning grows, we can easily imagine
the function arguments will grow impractically large. To get the Higgs
mass, we will need to feed them all the history of research that led
to the measurement of it.

There is the source of nondeterminism for Earth mass we will always use.

Is there a way to represent this? For example, can we define
earthMass'' , sunMass'' , marsMass'' all in separate modules, and yet
have (length $ sunPerMars'' == 27) ?



By the way,
*Main length $ nub $ sort sunPerMars'
16

is not 9. That's another story, I said!

Thanks in advance.
-- 
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] Any good tool to write Haskell documents including tests?

2012-07-10 Thread Takayuki Muranushi
Hello,

I have been a forgetful person, and lots of things I have only
pretended to understand. I want to change this. So, to educate myself,
I'd like to write documented tests for many libraries I meet, and also
publish them onto the web so that others may find them useful or find
mistakes for me. OK, blog articles are good, but they have no (forced)
tests.

Maybe some of you have practiced this or developping such tools. I see
some candidate tools, too. What is your suggestion for this?

I have tried doctest, because of its read–eval–print loop (REPL) style I liked.

https://github.com/nushio3/practice/tree/master/control-monad-loop

It produces html as attached to this mail. It's pretty, but I'd like
to have more control on HTML.
Maybe Gitit + Doctest in Pandoc is a good alternative?



I'd also like to know what is a good way to publish a small executable
examples with automated dependency install capability. Can you point
out any problems with following Makefile + cabal ? What are better
ways to do this?

https://github.com/nushio3/practice/blob/master/control-monad-loop/Loop.cabal
https://github.com/nushio3/practice/blob/master/control-monad-loop/Makefile

Thanks in advance,

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


MyFirstLoop.pdf
Description: Adobe PDF document
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Any good tool to write Haskell documents including tests?

2012-07-10 Thread Takayuki Muranushi
Thank you for your quick response!

I have used QuickCheck, but SmallCheck I didn't. Thank you! Then I'll
try to build such tests into Gitit.

2012/7/11 Strake strake...@gmail.com:
 On 10/07/2012, Takayuki Muranushi muranu...@gmail.com wrote:
 Hello,

 I have been a forgetful person, and lots of things I have only
 pretended to understand. I want to change this. So, to educate myself,
 I'd like to write documented tests for many libraries I meet, and also
 publish them onto the web so that others may find them useful or find
 mistakes for me. OK, blog articles are good, but they have no (forced)
 tests.

 Maybe some of you have practiced this or developping such tools. I see
 some candidate tools, too. What is your suggestion for this?

 I like SmallCheck myself. Define testable properties of the library,
 and SmallCheck will verify them for all cases to a given depth. The
 tests can be documented with Haddock like any Haskell code.

 http://hackage.haskell.org/package/smallcheck

 Another similar option is QuickCheck, which will randomly generate
 rather than enumerate.

 http://hackage.haskell.org/package/QuickCheck

 Cheers,
 Strake



-- 
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


Re: [Haskell-cafe] Two parallel libraries from Japan

2012-06-10 Thread Takayuki Muranushi
Hello everyone,

I, Takayuki, author of Paraiso, would like to make some follow ups.

First, the published version of the first paper on Paraiso is now
available from
http://iopscience.iop.org/1749-4699/5/1/015003 .
Please go ahead and read it because the typeset is better, the journal
is an open-access one and it has a most-read ranking!

Second, I have started to refactor Paraiso. Please refer to the blog
http://nushisblogger.blogspot.jp/search/label/ICFDP for the latest
specifications and examples. Comments are welcome!

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

2012/6/7 Kazu Yamamoto k...@iij.ad.jp

 Hello cafe,

 I would like to announce two parallel libraries from Japan.

 - Paraiso (http://hackage.haskell.org/package/Paraiso)

    The purpose of this library is to design a high-level language for
    implementing explicit partial-differential equations solvers on
    supercomputers as well as today's advanced personal computers.

    Muranushi-san is also known as the author of Monadius and one of
    the two translators of Learn you.

 - GTALib (http://hackage.haskell.org/package/GTALib)

    This package provides the core functionalities of the GTA
    (Generate, Test, and Aggregate) programming framework on Haskell
    See Test, and Aggregate - A Calculation-based Framework for
    Systematic Parallel Programming with MapReduce for more
    information.

 Regards,

 --Kazu

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


[Haskell-cafe] fixity declaration in GHCi

2012-01-16 Thread Takayuki Muranushi
Hello everyone,

while I'm playing with fixity declaration in GHCi, I found a strange
behavior. Can anyone explain this?
Is this actually an expected behavior, or is it a glitch?


$ ghci
GHCi, version 7.0.3: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Prelude minus--(1)

interactive:1:1: Not in scope: `minus'
Prelude let minus x y = x-y; infixl 6 `minus`--(2)
Prelude 10^5 `minus` 2--(3)
1000
Prelude let infixl 6 `minus`--(4)

interactive:1:14:
The fixity declaration for `minus' lacks an accompanying binding
Prelude let subtract x y = x-y--(5)
Prelude 10^5 `subtract` 2--(6)
1000
Prelude let f x y = x-y; infixl 6 `f` in 10^5 `f` 2--(7)
8
Prelude


(1) suggests that `minus` is not defined here. in (2), I try to define
`minus` with precedence level 6.
However, (3) suggests that precedence level of `minus` is stronger than ^ .

(4) suggests that you cannot redefine fixity here.
(5)(6) is consistent with Haskell 98 report section 4.4.2; Any
operator lacking a fixity declaration is assumed to be infixl 9.
in (7), precedence level is set as expected.

So, what is happening in (3)? Where did the fixity declaration in (2) went?

Best,

-- 
MURANUSHI Takayuki
The Hakubi Center, Kyoto University : http://www.hakubi.kyoto-u.ac.jp/

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