Re: [Haskell-cafe] Proposal: Non-recursive let

2013-07-17 Thread Markus Läll
For what it's worth, I think a non-recursive in the language would
just bring more confusion, in forums, IRC and whereever. The benefits
don't seem important at all, and the same effect can be achieved
through other means.

On Wed, Jul 17, 2013 at 2:20 AM, Richard A. O'Keefe o...@cs.otago.ac.nz wrote:
 Brian Marick sent me a couple of his stickers.
 The one I have on my door reads to be less wrong than yesterday.
 The other one I keep free to bring out and wave around:

 An example would be handy about now.

 All of the arguing to and fro -- including mine! -- about
 non-recursive let has been just so much hot air.  I could
 go on about how the distinction between 'val' and 'val rec'
 in ML was one of the things I came to dislike intensely,
 and how Haskell's single coherent approach is one of the
 things that attracted me to Haskell.

 But why should anyone else care?

 When presented with a difficulty, it is very common for some
 functional language users to propose adding just one more
 feature from some other language, commonly an imperative one
 (which ML, Caml, and F# arguably are).  Typically this is
 something that _would_ solve the immediate problem but would
 create worse problems elsewhere, and there is some other
 solution, either one already available in the language, or a
 better one that would solve additional problems or cause
 fewer ones.

 The best help for any discussion is A CONCRETE EXAMPLE OF
 REAL CODE.  Not little sketches hacked up for the purpose
 of discussion, but ACTUAL CODE.  The person who initially
 proposes a problem may think some details are not relevant,
 whereas someone else may see them as the key to the solution.

 For example, looking at some code in another mostly-
 functional language, which had been presented as reason why
 we needed a new construct, I rewrote it in less than half
 the number of lines using existing constructors, using only
 existing features.

 Without seeing THE ACTUAL CODE that prompted this thread,
 it is impossible to tell whether that might be the case here.

 In this specific case, we are seeing state being threaded
 through a bunch of updates, and IN THE ABSENCE OF THE ACTUAL
 CODE, it seems to me that monad notation is the most
 intention-revealing notation available for the purpose in
 Haskell, and if Haskell did have non-recursive let it would
 STILL be best to write such code using a state monad so that
 human beings reading the Haskell code would have some idea
 of what was happening, because that's how state changes are
 supposed to be expressed in Haskell, and anything else
 counts as obfuscation.

 But THE ACTUAL CODE might show that this case was different
 in some important way.



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



-- 
Markus Läll

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


Re: [Haskell-cafe] default instance for IsString

2012-04-22 Thread Markus Läll
Hi Greg

You *can* have what you want -- enable extended defaulting and set
Text as default by

 {-# LANGUAGE ExtendedDefaultRules #-}
 default (Integer, Double, T.Text) -- keep the default defaults

At the moment you only by chance have one instance of NoDefault in
scope, which is why it shouldn't work at the moment.

(ExtendedDefaultRules is required because the standard defaulting
rules apply only when defaulting numeric literals.)

On Sun, Apr 22, 2012 at 7:55 AM, Greg Weber g...@gregweber.info wrote:
 This is a better demonstration of the issue. I am going to open a GHC
 bug report, as I can't see how this behavior is desirable.


 {-# LANGUAGE OverloadedStrings #-}
 import Data.Text as T

 class    NoDefault a      where noDefault :: a - Text
 instance NoDefault T.Text where noDefault = id

 main = print (noDefault Hello!)

 default.hs:7:15:
    Ambiguous type variable `a0' in the constraints:
      (NoDefault a0) arising from a use of `noDefault'
                     at default.hs:7:15-23
      (Data.String.IsString a0) arising from the literal `Hello!'
                                at default.hs:7:25-32
    Probable fix: add a type signature that fixes these type variable(s)
    In the first argument of `print', namely `(noDefault Hello!)'
    In the expression: print (noDefault Hello!)
    In an equation for `main': main = print (noDefault Hello!)


 On Sat, Apr 21, 2012 at 7:51 PM, Greg Weber g...@gregweber.info wrote:
 my actual use case looks more like this:

 {-# LANGUAGE OverloadedStrings #-}
 {-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-}

 import Data.Text as T

 class ShowT a where
   showT :: a - String

 instance ShowT T.Text where
   showT = show

 instance ShowT String where
   showT = show

 main = print (showT Hello!)

    Ambiguous type variable `a0' in the constraints:
      (ShowT a0) arising from a use of `showT' at default.hs:16:15-19
      (Data.String.IsString a0) arising from the literal `Hello!'


 So I actually want to define a default instance for a typeclass I
 define that uses isString instances.



 On Sat, Apr 21, 2012 at 6:24 PM, Daniel Peebles pumpkin...@gmail.com wrote:
 I think it'll be hard to do that without putting Text in base, which I'm not
 sure anyone wants to do.

 Dan

 On Sat, Apr 21, 2012 at 8:20 PM, Greg Weber g...@gregweber.info wrote:

 I would like to default IsString to use the Text instance to avoid
 ambiguous type errors.
 I see defaulting capability is available for Num. Is there any way to
 do this for IsString?

 Thanks,
 Greg Weber

 ___
 Glasgow-haskell-users mailing list
 glasgow-haskell-us...@haskell.org
 http://www.haskell.org/mailman/listinfo/glasgow-haskell-users



 ___
 Glasgow-haskell-users mailing list
 glasgow-haskell-us...@haskell.org
 http://www.haskell.org/mailman/listinfo/glasgow-haskell-users



-- 
Markus Läll

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


Re: [Haskell-cafe] default instance for IsString

2012-04-22 Thread Markus Läll
The core of it is in the GHC docs' overloaded strings section [1].

It could be clearer though -- reading about defaulting in the reports,
in the type defaulting section of GHC docs and in [1] can be a bit
confusing.

[1] 
http://www.haskell.org/ghc/docs/latest/html/users_guide/type-class-extensions.html#overloaded-strings

On Sun, Apr 22, 2012 at 4:54 PM, Greg Weber g...@gregweber.info wrote:
 Thanks Markus, I think you have saved the day!
 Even after googling for this extension and searching in the manual I
 am still coming up pretty blank.
 Is there somewhere I missed where this is documented or somewhere I
 can contribute documentation?

 On Sun, Apr 22, 2012 at 4:47 AM, Markus Läll markus.l...@gmail.com wrote:
 ExtendedDefaultRules



-- 
Markus Läll

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


Re: [Haskell-cafe] default instance for IsString

2012-04-22 Thread Markus Läll
Isn't this a special case already?

I.e you already can default a string literal to anything you want, the
only thing needed is a language pragma (and more obvious docs). The
only problem is, that it's not part of the Haskell2010 report, and
thus not supported in other compilers (or is it?).

On Sun, Apr 22, 2012 at 8:51 PM, Johan Tibell johan.tib...@gmail.com wrote:
 On Sun, Apr 22, 2012 at 10:37 AM, Brent Yorgey byor...@seas.upenn.edu wrote:
 I do not think this is a bug.  Since type classes are open, GHC does
 not do any reasoning of the form X is the only instance in scope, so
 I will pick that one.  Other instances could be added at any time
 (perhaps in other modules).  In this particular instance, GHC has no
 reason to choose the Text instance other than the fact that it is the
 only instance in scope -- that is, type inference is not enough to
 determine that the Text instance should be chosen.

 However, I do agree that it would be nice to have a mechanism for
 specifying default instances for arbitrary (user-defined) type
 classes.

 Couldn't we make a special case for IsString, like we do for Num,
 given it's special syntactic association with OverloadedStrings?

 -- Johan

 ___
 Glasgow-haskell-users mailing list
 glasgow-haskell-us...@haskell.org
 http://www.haskell.org/mailman/listinfo/glasgow-haskell-users



-- 
Markus Läll

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


Re: [Haskell-cafe] [haskell-cafe] Some reflections on Haskell

2012-02-14 Thread Markus Läll
What about hoogle/hayoo and hackage?

On Tue, Feb 14, 2012 at 5:13 PM, Doug McIlroy d...@cs.dartmouth.edu wrote:
 Kevin Jardine notices the full Haskell ecosystem ... is huge, and
 laments the absence of a sophisticated IDE to help manage it.
 Being a small-code type, I don't personally enjoy IDE's, which
 are undeniably useful in big projects, at the cost of a whole lot
 more to learn about programmering in addition to programming.

 Nevertheless, I share Jardine's concern about the central problem.
 It is hard to find one's way in this ecosystem.  It needn't be,
 as Java illustrates.  To my mind Java's great contribution to the
 world is its library index--light years ahead of typical
 documentation one finds at haskell.org, which lacks the guiding
 hand of a flesh-and-blood librarian.  In this matter, it
 seems, industrial curation can achieve clarity more easily than
 open source.

 (To avoid entanglement with social media, this comment is going
 to Haskell Cafe rather than Google+ where other comments reside.)

 Doug McIlroy

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



-- 
Markus Läll

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


Re: [Haskell-cafe] Type class for sequences with dependent types

2012-01-05 Thread Markus Läll
Hi

This has been discussed here[1] and here[2], and the answer is that
its not possible because of making type inference generally
impossible. It would be a useful feature though, and could be
implemented by requiring the user give additional type signatures to
help the inference algorithm out. But that is AFAIK not implemented
yet.

[1] http://www.haskell.org/pipermail/haskell-cafe/2011-July/093790.html
[2] http://comments.gmane.org/gmane.comp.lang.haskell.glasgow.user/21017

On Thu, Jan 5, 2012 at 3:12 PM, Robbert Krebbers
mailingli...@robbertkrebbers.nl wrote:
 Hello,

 in a Haskell development I have to represent paths that have elements of
 alternating types. GADTs allow me to do this easily:

 data AltList :: * - * - * where
  Nil   :: AltList a a
  ICons :: Int - AltList Int b - AltList () b
  UCons :: () - AltList () b - AltList Int b

 Since I have various kinds of these data structures I defined a type class
 for common operations on such data structures.

 class DepSequence l where
  nil :: l a a
  app :: l a b - l b c - l a c

 The instance for AltList is as follows:

 instance DepSequence AltList where
  nil = Nil
  Nil       `app` k = k
  ICons i l `app` k = ICons i (l `app` k)
  UCons i l `app` k = UCons i (l `app` k)

 This all works nicely, however, I also want ordinary lists to be an instance
 of this class too. I tried the following:

 type IntListAlt a b = [Int]
 instance DepSequence IntListAlt where
  nil = []
  app = (++)

 But GHC does not like this, it yields:

  Type synonym `IntListAlt' should have 2 arguments, but has been
  given none In the instance declaration for `DepList IntListAlt'

 The following alternative works, but it is quite ugly

 newtype IntList a b = IntList { getList :: [Int] }
 instance DepSequence IntList where
  nil     = IntList []
  app l k = IntList (getList l ++ getList k)

 and also does not give me a nil of type [Int] and an app of type [Int] -
 [Int] - [Int].

 Does anyone know whether Haskell allows me to do this in a better way?

 Best,

 Robbert

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



-- 
Markus Läll

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


Re: [Haskell-cafe] How to split this string.

2012-01-02 Thread Markus Läll
String is really for small strings. Text is more efficent and also has
more functionality, including most, if not all, of the functions
defined for String.

On Mon, Jan 2, 2012 at 3:12 PM, Anupam Jain ajn...@gmail.com wrote:
 On Mon, Jan 2, 2012 at 5:52 PM, Felipe Almeida Lessa
 felipe.le...@gmail.com wrote:
 On Mon, Jan 2, 2012 at 10:12 AM, max m...@mtw.ru wrote:
 This is the simplest solution of the proposed, in my opinion. Thank you
 very much.

 Better yet, don't use String and use Text.  Then you just need
 T.splitOn \r\n [1].

 That is actually the opposite of what the OP wants, however it's
 interesting that Text has a function like that and not the String
 functions in the standard
 library.

 -- Anupam

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



-- 
Markus Läll

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


Re: [Haskell-cafe] Tupling functions

2011-09-15 Thread Markus Läll
Using fundeps I came up with this:

class T funs arg res | funs - arg res, arg res - funs where
   tuple :: funs - arg - res

instance (a ~ a0, a0 ~ a1) = T (a0 - b, a1 - c) a (b, c) where
   tuple (f, g) a = (f a, g a)

instance (a ~ a0, a0 ~ a1, a1 ~ a2) = T (a0 - b, a1 - c, a2 - d) a
(b, c, d) where
   tuple (f, g, h) a = (f a, g a, h a)


Intuitively it seems to be exactly the same as the type families'
aproach, and looks quite clear too.


On 9/15/11, Richard O'Keefe o...@cs.otago.ac.nz wrote:

 On 14/09/2011, at 2:45 PM, Casey McCann wrote:


class Tuple t where
type Arg t :: *
type Result t :: *
tuple :: t - Arg t - Result t

instance (x1 ~ x2) = Tuple (x1 - a, x2 - b) where
type Arg (x1 - a, x2 - b) = x1
type Result (x1 - a, x2 - b) = (a, b)
tuple (f, g) x = (f x, g x)

 That's it, that's what I was after.  Thanks.


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



-- 
Markus Läll

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


Re: [Haskell-cafe] ANN: fix-imports-0.1.2

2011-07-13 Thread Markus Läll
I have used it a little and it worked quite nicely.

One thing that to look out for though is that it first checks for
modules from the current directory down -- so running it in somewhere
you happen to have ghc sources too, will have all that come with it
imported from there (and lines like import path.to.ghc.DataMaybe
(fromJust) added). But this probably happens only when testing the
program in the root of your home directory...

(The reason I'm not using it regularly is that I haven't figured out a
good way to use it, when developing with Notepad++ over sftp in
another environment)


-- 
Markus Läll

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


[Haskell-cafe] Arrow instance of function type [a] - [b]

2011-07-06 Thread Markus Läll
Hi!

Is it possible to define an Arrow instance of list to list functions?
Something like

import Control.Arrow
import Control.Category

type X a b = [a] - [b]

instance Category X where
   id = map Prelude.id
   g . f = g Prelude.. f

instance Arrow X where
   arr f = map f
   first f = unzip  first f  uncurry zip

The problem is that it's not allowed to use partially applied type
synonyms. It is however possible to define a type synonym which value
is a partially applied type, but I haven't been able to figure out if
I could somehow use that fact in defining the X... Is it at all
possible, or is a newtype the only way to do it?


-- 
Markus Läll

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


Re: [Haskell-cafe] The Lisp Curse

2011-05-20 Thread Markus Läll
What's stopping it from being put on the official hackage? I use it quite a
lot to find well established packages and/or example code, and am quite fond
of it. But it is only visible when you know that this exists.

On Fri, May 20, 2011 at 10:28 AM, Roel van Dijk vandijk.r...@gmail.comwrote:

 On 19 May 2011 20:50, Serguey Zefirov sergu...@gmail.com wrote:
  The solution... I think that some ratings, like used directly by ###
  packages/projects and indirectly by ### would be nice, but not much.

 Maybe my reverse dependencies mirror of hackage could be useful here:
 http://bifunctor.homelinux.net/~roel/hackage/packages/hackage.html

 The mirror was intended to show the workings of a patch for the old
 (current) hackage. It is updated daily.

 The algorithm needs some attention so don't trust it blindly, but in
 general it is quite accurate.

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




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


Re: [Haskell-cafe] Reverse Show instance

2011-05-19 Thread Markus Läll
If you have nested type, then it usually makes sense to have Show defined
for the inside types, too, but it's not a requirement. Technically, only
when you call 'show' for something in the data type you are defining Show
for, *then* you need a Show instance defined for that inside-type.

On Fri, May 20, 2011 at 12:15 AM, Andrew Coppin andrewcop...@btinternet.com
 wrote:

 On 19/05/2011 10:11 PM, Artyom Kazak wrote:

 And I can declare an instance for (x, y) which does NOT implies (Show x):

 instance Show (x, y) where
 show _ = I'm tuple! Hooray!


 Ah. So it's a feature.

 Fortunately I refactored the program where this came up, so it's no longer
 an issue. I just wanted to see whether or not it was a bug.

 PS. Wouldn't such an instance require FlexibleContexts or something?


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




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


Re: [Haskell-cafe] Local copy of hackageDB

2011-04-07 Thread Markus Läll
This could be a nice feature and not hard to implement, maybe someone could
take it up?

2011/4/7 José Pedro Magalhães j...@cs.uu.nl

 Yes, I have that tarball. I just don't know how to tell cabal-install to
 use it. Going to each package, individually unpacking and installing it is
 what I've been doing so far, but I was hoping that could be automated.


 Cheers,
 Pedro


 On Thu, Apr 7, 2011 at 14:18, Magnus Therning mag...@therning.org wrote:

 On Thu, Apr 7, 2011 at 11:21, Marc Weber marco-owe...@gmx.de wrote:
  Local copy ?
  You know that hackage is hosting several thausands of source archives -
  also old versions you don't want?
 
  Do you want to mirror everything locally?
 
  Fetching latest versions only to generate hashes takes many hours.
  (Experience from hack-nix).

 There's a tar-ball served from
 http://hackage.haskell.org/packages/hackage.html
 (http://hackage.haskell.org/cgi-bin/hackage-scripts/archive.tar) which
 contains the latest version of all packages.  I think that's what the
 OP is using.  Downloading a 150MB tar-ball shouldn't take many hours,
 if you're on a decent connection.

 /M

 --
 Magnus Therning  OpenPGP: 0xAB4DFBA4
 email: mag...@therning.org   jabber: mag...@therning.org
 twitter: magthe   http://therning.org/magnus

 ___
 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] [Haskell-beginners] how to modify show for a list of certain types

2011-04-02 Thread Markus Läll
Check out unlines!

On Sat, Apr 2, 2011 at 4:32 PM, Manfred Lotz manfred.l...@arcor.de wrote:

 Hi there,
 I have a list of say type  Record which I write to a file and
 read back from the file if required.

 The list's content is a single line in the file it doesn't matter how
 many records the list contains.

 I would like to modify show for type Record in a way that show does
 work like the normal show but additionally adds a newline at the end of
 the string.

 I'm a bit lost how to do that. Any idea?


 --
 Manfred



 ___
 Beginners mailing list
 beginn...@haskell.org
 http://www.haskell.org/mailman/listinfo/beginners

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


Re: [Haskell-cafe] Learn You a Haskell for Great Good - a few doubts

2011-03-04 Thread Markus Läll
Sorry, I didn't mean to answer you in particular. I meant to say that for
tuples you could (I think) have an enumeration over them without requiring
any component be bounded.

An example of type (Integer, Integer) you would have:

[(0,0) ..] = [(0,0) (0,1) (1,0) (0,2) (1,1) (2,0) ... ]

where the order can be visualized by taking diagonals of a table starting
from the upper left:

0  1  2 ..
0 (0,0)  (0,1)  (0,2)
1 (1,0)  (1,1)  (1,2)
2 (2,0)  (2,1)  (2,2)
..

Would this also have an uncomputable order type? At least for comparing
tuples you'd just:

lt :: (Integer,Integer) - (Integer,Integer) - Bool
(a,b) `lt` (c,d) = let
  sum1 = (a + b)
  sum2 = (c + d)
   in if sum1 == sum2
 then a  c
 else sum1  sum2


Implementing fromEnum looks like a bit harder problem..


--
Markus Läll




On Fri, Mar 4, 2011 at 5:12 AM, Daniel Fischer 
daniel.is.fisc...@googlemail.com wrote:

 On Friday 04 March 2011 03:24:34, Markus wrote:
  What about having the order by diagonals, like:
 
  0 1 3
  2 4
  5
 
  and have none of the pair be bounded?
 

 I tacitly assumed product order (lexicographic order).
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell IDE

2011-03-03 Thread Markus Läll
I have been using Notepad++ -- it has proper (I think) syntaks highlighting
and in the latest version now has line wrapping a la kate: broken lines
start at the indent level of the first one.

--
Markus Läll

On Fri, Mar 4, 2011 at 1:14 AM, Daniel Fischer 
daniel.is.fisc...@googlemail.com wrote:

 On Thursday 03 March 2011 22:14:34, Michael Xavier wrote:
  I use vim (CLI not gvim).

 I use kate.

 ___
 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: ANN: vector-buffer package 0.1

2011-02-15 Thread Markus Läll
Hi, Alexander

Here's my take on why the code isnt right:

In the let the v1 and v2 get lazyly bound to code that calls
unsafePerformIO. unsafePerformIO does side-effectful things, but works
outside the IO monad and thus outside the main order of IO actions.

If you create a buffer, push something in and make two lists of it -- v1
and v2 -- then they don't get evaluated to concrete lists (weak head
normal form?) right away, but when they are actually needed. So if you print
v1, buf is read and converted into a list (and printed). v2 stays
unevaluated, but bound to the value of buf. So if you change buf, then
v2 is bound to be different too.

This breaks referential transperency because v1 and v2 by theire
definitions should be exactly the same. And the breakage can only happen
because of using unsafePerformIO, which allowes you to go out in the IO
world and get stuff, but bypass the order of evaluation that IO monad forces
you to otherwise have.


Someone correct me if I'm wrong :)


--
Markus Läll


On Tue, Feb 15, 2011 at 8:08 AM, Alexander McPhail 
haskell.vivian.mcph...@gmail.com wrote:

 Hi list,

 Could someone explain why the error pointed out by Luke occurred?

 From: Luke Palmer lrpal...@gmail.com

 I think this would be a very good question for the list.  Don't worry,
 they're nice helpful folks.

 On Mon, Feb 14, 2011 at 10:10 PM, Alexander McPhail
 haskell.vivian.mcph...@gmail.com wrote:
  Hi Roman,
 
 
  Can you explain why the following code doesn't work?  'unsafePerformIO'
 is
  used all the time in hmatrix.  For example, adding two vectors, we create
 a
  new Vector then use that as the target for an FFI C call.
 
  Is the difference because I'm using mutable Storable Vectors?  I would
 have
  thought that unsafeFreeze (at the end) would make sure the problem
 reported
  by Luke wouldn't occur.
 
  Is there a problem with laziness in the let binding of Luke's example?
 
  I note that in Data.Vector.Storable there is a pure 'convert' function,
  which is essentially what I am trying to emulate.
 
  -- | convert to a vector
  toVector :: Storable a = Buffer a - (V.Vector a)
  toVector (B o n v) = unsafePerformIO $ do
 w - M.new n
 i - readIORef o
 M.unsafeWith v $ \p -
 M.unsafeWith w $ \q - do
   let n' = n-i
   copyArray q (p `advancePtr` i) n'
   if i /= 0
  then copyArray (q `advancePtr` n') p i
  else return ()
 V.unsafeFreeze w
  {-# INLINE toVector #-}
 
 
  Vivian
 
  From: Luke Palmer lrpal...@gmail.com

 
  This interface is an outlaw.
 
  main = do
 buf - newBuffer 10 :: IO (Buffer Int)
 pushNextElement buf 1
 let v1 = V.toList (toVector buf)
 v2 = V.toList (toVector buf)
 print v1
 pushNextElement buf 2
 print v2
 
  Despite v1 and v2 being defined to equal the exact same thing, this
  program prints two distinct lines.
 
  toVector depends on the current state of the buffer.  If this is to be
  a law-abiding interface, toVector must return a value in IO:
 
 toVector :: (Storable a) = Buffer a - IO (Vector a)
 
  Luke
 

 ___
 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] Proving correctness

2011-02-11 Thread Markus Läll
I think one thing it means, is that, with the typesystem, you just can't do
random things where-ever you want. Like, in the pure world if you want to
transform values from one type to another, you always need to have
implementations of functions available to do that. (You can't just take a
pure value, get its mem location and interpret it as something else, without
being explicid about it.) So when lining up your code (composing functions),
you can be sure, that at least as far as types are concerned, everything is
correct -- that such a program, that you wrote, can actually exist == that
all the apropriate functions exist.

And it is correct only that far -- the value-level coding is still up to
you, so no mind-reading...


--
Markus Läll

On Fri, Feb 11, 2011 at 1:16 PM, Ivan Lazar Miljenovic 
ivan.miljeno...@gmail.com wrote:

 On 11 February 2011 22:06, C K Kashyap ckkash...@gmail.com wrote:
  Hi Folks,
  I've come across this a few times - In Haskell, once can prove the
  correctness of the code - Is this true?

 I'm not quite sure where you got that...

 But since Haskell is pure, we can also do equational reasoning, etc.
 to help prove correctness.  Admittedly, I don't know how many people
 actually do so...

  I know that static typing and strong typing of Haskell eliminate a whole
  class of problems - is that related to the proving correctness?
  Is it about Quickcheck - if so, how is it different from having test
 sutites
  in projects using mainstream languages?

 QuickCheck doesn't prove correctness: I had a bug that survived
 several releases tested regularly during development with a QC-based
 testsuite before it arose (as it required a specific condition to be
 satisfied for the bug to happen).  As far as I know, a testsuite - no
 matter what language or what tools/methodologies are used - for a
 non-trivial piece of work just provides reasonable degree of assurance
 of correctness; after all, there could be a bug/problem you hadn't
 thought of!

 --
 Ivan Lazar Miljenovic
 ivan.miljeno...@gmail.com
 IvanMiljenovic.wordpress.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


Re: [Haskell-cafe] How about Haskell Golf just like vimgolf.com

2011-01-04 Thread Markus Läll
On Mon, Jan 3, 2011 at 6:19 PM, Ertugrul Soeylemez e...@ertes.de wrote:

 Alex Kropivny alex.kropi...@gmail.com wrote:

  Could something like code abstraction be done instead?
 
  Haskell lends itself to solving problems in really generic, high level
  ways that reveal a LOT about the underlying problem structure. Through
  some combination of descriptive data types, generic type classes, and
  generic helper functions... You get an extremely clear problem
  description.
 
  Example: https://github.com/amtal/snippets/blob/master/Key.hs (Haskell)
  versus http://siyobik.info/index.php?module=pastebinid=543 (C++)
 
  Clarity is a lot harder to score for, so you'd probably need to score
  things via votes. (Unless there's a way to measure how
  generic/high-level code is?) Such a site would fill a very nice
  role, that the programming language shootout definitely does not fill.
 
  Currently the only way to figure out what good Haskell code looks
  like is to browse lots of blogs, and dig through hackage until you
  find beautifully written packages.

 I really like this idea.  New concepts in Haskell come up from time to
 time.  Now if there was a competition for code quality and good ideas,
 they may become more frequent.


This could also go for problems, where you have to use some specific feature
or extension, like scoped type variables, type families/functional
dependencies, or even just typeclasses... (Remember, there was a deep list
concatenation problem thread some days ago.)

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


Re: [Haskell-cafe] record types and unique names

2010-12-30 Thread Markus Läll
Yes, they are in the global scope, and from what I gather: they are just
regular functions, created by special syntax.

There are a few obvious solutions (some of which you might have thought
yourself :-):
 - rename the accessor or the other function, or
 - put the data declaration or the other function in another module and
import qualified, or
 - write a typeclass with a 'name' function and fit the non-accessor
function 'name' somehow into that...

I think the best approach is the modular one, but this really depends on
what you are doing.

--
Markus Läll

On Thu, Dec 30, 2010 at 7:01 PM, Aaron Gray aaronngray.li...@gmail.comwrote:

 Given a Haskell record type :-

 data Test
 = Test {
 name :: String,
 value :: Int
 }

 test = Test {
 name = test,
 value = 1
 }

 main :: IO ()
 main = do
 putStrLn (name test)

 Are name and value in the global name space, as the following gives an
 error Multiple declarations of `name' :-

 name :: String - String
 name s = s

 Is there any way round this ?

 Many thanks in advance,

 Aaron


 ___
 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] Offer to mirror Hackage

2010-12-14 Thread Markus Läll
The reason for mirror was avilability, yes, and when the signatures were
only on the central sever, then the user could choose not to install
packages from mirrors, when they were not available.

But now if the signatures were generated by the uploader, then the morrors
would be just as secure as the central? I mean -- if we don't trust DNS,
then the main hackage has no special security advantages?


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


Re: [Haskell-cafe] Offer to mirror Hackage

2010-12-09 Thread Markus Läll
My take on the issue is that we should make it possible to easily mirror
hackage (what the OP asked for), so that people could use it when they
wanted to, and have a list of the mirrors on the wiki. This way those who
are interested can use them. Like when the mirror is faster/closer to them
or to help out when hackage is temporarily down. Those who need the security
can choose not to use mirrors, or make their own (private), or develop a
secure scheme, when it doesn't exist yet.

It's perfectly understandable, that people doing work/serious stuff need the
guarantees, but I bet a many of us are just playing around and developing
things for themselves.

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


Re: [Haskell-cafe] Offer to mirror Hackage

2010-12-09 Thread Markus Läll
On Thu, Dec 9, 2010 at 11:04 PM, Richard O'Keefe o...@cs.otago.ac.nz wrote:


 On 10/12/2010, at 12:18 AM, Markus Läll wrote:

  My take on the issue is that we should make it possible to easily mirror
 hackage (what the OP asked for), so that people could use it when they
 wanted to, and have a list of the mirrors on the wiki. This way those who
 are interested can use them. Like when the mirror is faster/closer to them
 or to help out when hackage is temporarily down. Those who need the security
 can choose not to use mirrors, or make their own (private), or develop a
 secure scheme, when it doesn't exist yet.

 Have I misunderstood something?
 I thought X is a mirror of Y meant X would be a read-only replica of Y,
 with some sort of protocol between X and Y to keep X up to date.
 As long as the material from Y replicated at X is *supposed* to be
 publicly available, I don't see a security problem here.  Only Y accepts
 updates from outside, and it continues to do whatever authentication it
 would do without a mirror.  The mirror X would *not* accept updates.


Yes, that's what I think of mirrors too. I don't know if that was what you
meant, but yes those mirrors would be just passive copies of the real
hackage server (no updates from a user), and serve as a place to download
packages from until the original hackage comes back.

But for the security issue, ofcourse any host of a mirror could abuse that.
But I think for non-critical stuff I wouldn't mind using the mirror if it
has shown to be trustworthy. And for people  using Haskell a lot, if the
making of your own mirror is as simple as installing some package on your
webserver and running it, then this would be a great remedy against those
hours when something has happened to hackage..

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


Re: [Haskell-cafe] type level program

2010-10-25 Thread Markus Läll
Not exactly answering your question, but just in case you hadn't
checked, there are a few packages for type level natural numbers on
hackage, which do the same things as the program below. The packages
are:
 - type-level-natural-number and co by Gregory Crosswhite, and
 - type-level-numers by Alexey Khudyakov (which does type-level binary
encoding(!) for natural numbers)

As for the terminology, I can't tell..

Out of intrest, is this kind of type-level stuff to prove things about
your container types and operations on them?

--
Markus Läll

On Mon, Oct 25, 2010 at 12:52 PM, Patrick Browne patrick.bro...@dit.ie wrote:
 Hi,
 I hypothesize that at type level Haskell offers a form of equational
 logic. At type level the following program[1] could be interpreted as a
 first order program in equational logic where;
 1)Data types represent declarations of constructors (both constants and
 functions)
 2)Type synonyms represent equations assigning constructors to variables
 3)Each class contains a non-constructor operation signature with
 dependencies
 4) instances contain equations that define the operations
  (similar the term rewriting systems (TRS) of  Maude/CafeOBJ).

 5):t acts as a reduction or evaluation at type level

 Is the a reasonable description of this program?

 Regards,
 Pat

 [1] From Fritz Ruehr
 http://www.willamette.edu/~fruehr/haskell/evolution.html

 -- static Peano constructors and numerals
 data Zero
 data Succ n

 type One   = Succ Zero
 type Two   = Succ One
 type Three = Succ Two
 type Four  = Succ Three


 -- dynamic representatives for static Peanos

 zero  = undefined :: Zero
 one   = undefined :: One
 two   = undefined :: Two
 three = undefined :: Three
 four  = undefined :: Four


 -- addition, a la Prolog

 class Add a b c | a b - c where
  add :: a - b - c

 instance              Add  Zero    b  b
 instance Add a b c = Add (Succ a) b (Succ c)


 -- multiplication, a la Prolog

 class Mul a b c | a b - c where
  mul :: a - b - c

 instance                           Mul  Zero    b Zero
 instance (Mul a b c, Add b c d) = Mul (Succ a) b d


 -- factorial, a la Prolog

 class Fac a b | a - b where
  fac :: a - b

 instance                                Fac  Zero    One
 instance (Fac n k, Mul (Succ n) k m) = Fac (Succ n) m

 -- try, for instance (sorry):
 --
 --     :t fac four

 This message has been scanned for content and viruses by the DIT Information 
 Services E-Mail Scanning Service, and is believed to be clean. 
 http://www.dit.ie
 ___
 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] What is -

2010-08-08 Thread Markus Läll
Hi Michael,

although I never used it myself, lists seem strange in the way that when
combining list monads, then all the values go through the chain one by one
-- x will be 1 first, then 2, then 3 and so on.. Try it out, to see. (I
think the result is then also a list of all combinations of results.)


On Sun, Aug 8, 2010 at 5:26 PM, Christopher Done
chrisd...@googlemail.comwrote:

 On 8 August 2010 16:21, michael rice nowg...@yahoo.com wrote:

 getLine = \x -  -- x is a string at this point

 [1..] = \x --- x is WHAT at this point?


 Num n = n

 A number from the list.

 ___
 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] Removing alternate items from a list

2010-06-10 Thread Markus Läll
Yep, the test is done by a rookie. If I get more time, I'll try to
look into testing a little more, and redo the timing (if anyone
doesn't do it firs) -- using optimizations, more runs per function and
the criterion package.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Removing alternate items from a list

2010-06-09 Thread Markus Läll
So out of curiosity i took the definitions given in this thread, and
tried to run timing-tests.
Here's what I ran:
 ghc -prof -auto-all -o Test Test.h
 Test +RTS -p
and then looked in the Test.prof file.

All tests I ran from 3 to 10 times (depending on how sure I wanted to
be), so the  results are not entirely exact. (I copied the average
result to the source-file as comments above every function.)

As the function doing (x:_:rest) pattern-matching was the fastest I
extended the idea from that to (x1:_:x2: ... x10:_:rest), but skipping
from 5 to 10, where all steps showed a small increase in performance.

So a question: when increasing the pattern matched, is it somekind of
way of inlining the matchings, and if so, is there some way of just
saying that to the compiler how many recursions you want to inline
together to increase speed?

Any comments? (besides -O2 ;-)  -- I remembered it too late and didn't
want to restart... At least for the last two functions it showed a
similar difference in seconds as with no -O2)


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


Re: [Haskell-cafe] Removing alternate items from a list

2010-06-09 Thread Markus Läll
Forgot the file -- here it is:

module Main where

import Data.Either (rights)
import Data.Function (fix)

test f = putStr $ show $ last $ f $ replicate 1000 (1 :: Int)

main = test matchPattern4
-- 1. zipNums
-- 2. matchPattern
-- 3. zipBoolCycle
-- 4. iterDrop
-- 5. zipBoolCycle2
-- 6. consume
-- 7. eitherr
-- 8. golf
-- 9. matchPattern2
-- 10. matchPattern3
-- 11. matchPattern4
-- 12. matchPattern5
-- 13. matchPattern10

-- 1. total time  =   13.72 secs   (686 ticks @ 20 ms)
--total alloc = 1,840,007,000 bytes  (excludes profiling overheads)
zipNums = map snd . filter (odd . fst) . zip [1,2..]

-- 2. total time  =1.82 secs   (91 ticks @ 20 ms)
--total alloc = 400,006,752 bytes  (excludes profiling overheads)
matchPattern (x:_:zs) = x : matchPattern zs
matchPattern x = x

-- 3. total time  =4.46 secs   (223 ticks @ 20 ms)
--total alloc = 1,040,006,904 bytes  (excludes profiling overhea
zipBoolCycle xs = map fst . filter snd $ zip xs (cycle [False, True])

-- 4 total time  =5.20 secs   (260 ticks @ 20 ms)
--   total alloc = 940,006,916 bytes  (excludes profiling overheads)
iterDrop = map head . takeWhile (not . null) . iterate (drop 2) . drop 1


-- 5 total time  =3.68 secs   (184 ticks @ 20 ms)
--   total alloc = 820,006,872 bytes  (excludes profiling overheads)
zipBoolCycle2 x = [y | (True, y) - zip (cycle [False, True]) x]


-- 6. total time  =2.46 secs   (123 ticks @ 20 ms)
--total alloc = 420,006,860 bytes  (excludes profiling overheads)
data Consume = Take | Skip
consumeBy :: [Consume] - [a] - [a]
consumeBy [] _ = []
consumeBy _ [] = []
consumeBy (tOrS:takesAndSkips) (x:xs) =
   case tOrS of Take - x : consumeBy takesAndSkips xs
Skip - consumeBy takesAndSkips xs
consume = consumeBy $ cycle [Take, Skip]


-- 7. total time  =4.10 secs   (205 ticks @ 20 ms)
--total alloc = 1,000,006,884 bytes  (excludes profiling overheads)
eitherr = rights . zipWith ($) (cycle [Left,Right])


-- 8. total time  =2.08 secs   (104 ticks @ 20 ms)
--total alloc = 420,006,784 bytes  (excludes profiling overheads)
golf = (fix $ \f xs - case xs of { (x:_: xs) - x : f xs; _ - [] })


-- 9. total time  =1.68 secs   (84 ticks @ 20 ms)
--total alloc = 370,006,752 bytes  (excludes profiling overheads)
matchPattern2 (a:_:c:_:rest)  = a : c : matchPattern2 rest
matchPattern2 (a:_:rest)  = a : rest
matchPattern2 (rest)  = rest

-- 10. total time  =1.58 secs   (79 ticks @ 20 ms)
-- total alloc = 360,006,744 bytes  (excludes profiling overheads)
matchPattern3 (a:_:c:_:e:_: rest) = a : c : e : matchPattern3 rest
matchPattern3 (a:_:c:_:rest)  = a : c : rest
matchPattern3 (a:_:rest)  = a : rest
matchPattern3 (rest)  = rest

-- 11. total time  =1.56 secs   (78 ticks @ 20 ms)
-- total alloc = 355,006,752 bytes  (excludes profiling overheads)
matchPattern4 (a:_:c:_:e:_:g:_:rest) = a : c : e : g : matchPattern4 rest
matchPattern4 (a:_:c:_:e:_: rest)= a : c : e : rest
matchPattern4 (a:_:c:_:rest) = a : c : rest
matchPattern4 (a:_:rest) = a : rest
matchPattern4 (rest) = rest

-- 12. total time  =1.52 secs   (76 ticks @ 20 ms)
-- total alloc = 352,006,752 bytes  (excludes profiling overheads)
matchPattern5 (a:_:c:_:e:_:g:_:i:_:rest) = a : c : e : g : i :
matchPattern5 rest
matchPattern5 (a:_:c:_:e:_:g:_:rest) = a : c : e : g : rest
matchPattern5 (a:_:c:_:e:_: rest)= a : c : e : rest
matchPattern5 (a:_:c:_:rest) = a : c : rest
matchPattern5 (a:_:rest) = a : rest
matchPattern5 (rest) = rest

-- 13. total time  =1.48 secs   (74 ticks @ 20 ms)
-- total alloc = 346,006,752 bytes  (excludes profiling overheads)
matchPattern10 (a:_:c:_:e:_:g:_:i:_:k:_:m:_:o:_:q:_:s:_:rest) =
a:c:e:g:i:k:m:o:q:s: matchPattern10 rest
matchPattern10 (a:_:c:_:e:_:g:_:i:_:k:_:m:_:o:_:q:_:rest) =
a:c:e:g:i:k:m:o:q:rest
matchPattern10 (a:_:c:_:e:_:g:_:i:_:k:_:m:_:o:_:rest) =
a:c:e:g:i:k:m:o:rest
matchPattern10 (a:_:c:_:e:_:g:_:i:_:k:_:m:_:rest) =
a:c:e:g:i:k:m:rest
matchPattern10 (a:_:c:_:e:_:g:_:i:_:k:_:rest) = a:c:e:g:i:k:rest
matchPattern10 (a:_:c:_:e:_:g:_:i:_:rest) = a:c:e:g:i:rest
matchPattern10 (a:_:c:_:e:_:g:_:rest) = a:c:e:g:rest
matchPattern10 (a:_:c:_:e:_: rest)= a:c:e:rest
matchPattern10 (a:_:c:_:rest) = a:c:rest
matchPattern10 (a:_:rest) = a:rest
matchPattern10 (rest) = rest

On Wed, Jun 9, 2010 at 11:47 PM, Markus Läll markus.l...@gmail.com wrote:
 So out of curiosity i took the definitions given in this thread, and
 tried to run timing-tests.
 Here's what I ran:
 ghc -prof -auto-all -o Test Test.h
 Test +RTS -p
 and then looked in the Test.prof file

Re: [Haskell-cafe] Haskell, Queries and Monad Comprehension

2010-05-25 Thread Markus Läll
I would be intrested in seeing this! Could you paste or upload it somewhere?


2010/5/24 C. McCann c...@uptoisomorphism.net:
 2010/5/23 Günther Schmidt gue.schm...@web.de:
 is there anybody currently using Haskell to construct or implement a query
 language?

 I've a half-baked, type-indexed (in HList style) implementation of
 relational algebra lying around somewhere, if that counts as a query
 language. I was experimenting with using it as a sort of abstract
 collection interface, which actually worked rather nicely I think, but
 I didn't have time to flesh it out completely. In particular, only
 very simple queries and limited kinds of relation composition were
 supported. Definitely just toy code, though, and dreadfully
 inefficient; if you're looking for an actual implementation meaning
 usable interface to an external persistence layer then disregard
 this.

 - C.
 ___
 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