Re: [Haskell-cafe] Assembly EDSL in Haskell
You have fixed the type of list by move RAX RAX. Now it has type Instruction SNDREG SNDREG Make your Instruction a GADT and require that MOV should have appropriate constraints: {-# LANGUAGE DatatypeContexts, GADTs #-} data SREG = RIP data DREG = RBX data SNDREG = RAX data Instruction where MOV :: (Source s, Destination d) => s -> d -> Instruction class Source a class Destination a instance Source SREG instance Source SNDREG instance Destination DREG instance Destination SNDREG move :: (Source s, Destination d) => s -> d -> Instruction move s d = MOV s d hello = [move RAX RAX, move RAX RAX] hello2 = [move RAX RAX, move RAX RBX] -- this is still not allowed. 2013/4/1 C K Kashyap > Hi Cafe, > I am trying to embed x86 assembly in Haskell. I'd like the EDSL to not > allow invalid movements into registers - for example, should not allow > moving into RIP. I was not able to get it to work. I ended up using > DataTypeContexts - which is considered misfeature anyway. I was wondering > if I could get some suggestions. > > {-# LANGUAGE DatatypeContexts #-} > > data SREG = RIP > data DREG = RBX > data SNDREG = RAX > > > data (Source s, Destination d) => Instruction s d = MOV s d > > > class Source a > class Destination a > > instance Source SREG > instance Source SNDREG > > instance Destination DREG > instance Destination SNDREG > > > move :: (Source s, Destination d) => s -> d -> Instruction s d > move s d = MOV s d > > hello = [move RAX RAX, move RAX RAX] > > hello = [move RAX RAX, move RAX RBX] -- this is still not allowed. > > Regards, > Kashyap > > > ___ > 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] Race Condition in threads
2012/12/18 mukesh tiwari : > Hello All > I have two questions. > 1. I wrote this code to create 10 simultaneous threads. Could some one > please tell me if this is correct or not ? > > incr_count :: MVar () -> MVar Int -> IO () > incr_count m n = ( forM_ [ 1..1 ] $ \_ -> modifyMVar_ n ( return . ( + > 10 ) ) ) >> putMVar m () > > main :: IO() > main = do > count <- newMVar 0 > list <- forM [1..10] $ \_ -> newEmptyMVar > forM_ list $ \var -> forkIO . incr_count var $ count > forM_ list $ \var -> takeMVar var > val <- takeMVar count > print val It is pretty much correct (some comments would be nice, though). > 2. I am trying to create race condition which makes the variable in > inconsistent state. Could some one please tell me how to achieve this ? I > look at IORef but it does not have function like modifyMVar_. MVars are "atomic" in the sense that they have empty state and mutator can wait until variable will have a value. So you have to operate with something else, either IORef or with readMVar instead of takeMVar or modifyMVar_. > Mukesh Tiwari > > ___ > 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] C++
This array is for dynamic programming. You can diagonalize it into a list and use technique similar to the Fibonacci numbers. The resulting solution should be purely declarative. 2012/12/11 mukesh tiwari : > Hello All > I am trying to transform this C++ code in Haskell. In case any one > interested this is solution of SPOJ problem. > > #include > #include > #include > using namespace std; > > int memo[1100][1100] ; > > int recurse( int h , int a , int cnt , bool flag ) > { > if ( h <= 0 || a <= 0 ) return cnt ; > if ( memo[h][a] ) return memo[h][a] ; > if ( flag ) memo[h][a] = recurse ( h + 3 , a + 2 , cnt + 1 , !flag ) > ; > else > memo[h][a] = max ( memo[h][a] , max ( recurse ( h - 5 , a - 10 , > cnt + 1 , !flag ) , recurse ( h - 20 , a + 5 , cnt + 1 , !flag ) ) ) ; > > return memo[h][a]; >} > > int main() > { > int n , a , b ; > scanf( "%d", &n ); > for(int i = 0 ; i < n ; i++) > { > memset ( memo , 0 , sizeof memo ) ; > scanf("%d%d", &a , &b ); > printf("%d\n" , recurse( a , b , -1 , 1 )); > if( i != ( n - 1 ) ) printf("\n"); > } > > } > > I am stuck with that memo[1100][1100] is global variable so I tried to solve > this problem using state monad ( Don't know if its correct approach or not ) > but it certainly does not seem correct to me. Till now I came up with code. > Could some one please tell me how to solve this kind of problem ( Generally > we have a global variable either multi dimensional array or map and we > store the best values found so far in the table ). > > import qualified Data.Map.Strict as SM > import Control.Monad.State > > {-- > funsolve_WF :: Int -> Int -> Int -> Int > funsolve_WF h a cnt > | h <= 0 || a <= 0 = cnt > | otherwise = funsolve_Air h a ( cnt + 1 ) > > funsolve_Air :: Int -> Int -> Int -> Int > funsolve_Air h a cnt = max ( funsolve_WF ( h + 3 - 5 ) ( a + 2 - 10 ) cnt' ) > ( funsolve_WF ( h + 3 - 20 ) ( a + 2 + 5 ) cnt' ) where > cnt' = cnt + 1 > --} > > > > funSolve :: Int -> Int -> Int -> Bool -> State ( SM.Map ( Int , Int ) Int ) > Int > funSolve hl am cnt f > | hl <= 0 && am <= 0 = return cnt > | otherwise = do > mp <- get > case () of >_| SM.member ( hl , am ) mp -> return mp SM.! ( hl , am ) > | f -> do > --here I have to insert the value return by function > funSolve ( hl + 3 ) ( am + 2 ) ( cnt + 1 ) ( not f ) to map whose key is ( > hl , am ) > let k = evalState ( funSolve ( hl + 3 ) ( am + 2 ) > ( cnt + 1 ) ( not f ) ) mp > modify ( SM.insert ( hl , am ) k ) > > > | otherwise -> do >do > let k_1 = evalState ( funSolve ( hl - 5 ) ( am - 10 > ) ( cnt + 1 ) ( not f ) ) mp > k_2 = evalState ( funSolve ( hl - 20 ) ( am + 5 > ) ( cnt + 1 ) ( not f ) ) mp > k_3 = mp SM.! ( hl , am ) > modify ( SM.insert ( hl , am ) ( maximum [ k_1 , > k_2 , k_3 ] ) ) > > Regards > Mukesh Tiwari > > ___ > 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] Moscow Haskell Users Group (MskHUG) December meeting.
I would like to announce MskHUG December meeting and invite everyone interested. The meeting will take place December 13th, 20:00 to 23:30 in the nice conference center in centre of Moscow: http://www.nf-conference.ru/ The meeting's agenda is to start more intense discussions. Most probably, there will be a couple of short presentations - I can tell about creating fast Haskell programs to handle large data to start the discussion. I will bring white paper and pencils for everyone to write and draw, there will be projector and screen and also tea, cofee and snacks. If you want to participate, please, email me. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Wanted: Haskell binding for libbdd (buddy)
2012/8/20 Johannes Waldmann : > Are there any Haskell bindings for BDD libraries > (reduced ordered binary decision diagrams)? > > E.g., it seems "buddy" is commonly used > http://packages.debian.org/squeeze/libbdd-dev > and it has an Ocaml binding. > > Yes, there is http://hackage.haskell.org/package/obdd > but I need better performance (with the same API, ideally). > > Thanks - J.W. > > PS: I wonder where performance goes out the window ... > I suspect "Map (Int,Int) whatever" should really be > a hashtable but I don't like it in IO, it should be in ST? Actually, all Maps there should be IntMap's, strict ones. And yes, cache field should be two-level IntMap too. The type Index is good for external typed access, but internally one should use IntMap. > > > > ___ > 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] class instances for kinds with finite ty constrs, does this make sense?
2012/6/8 Brent Yorgey : > On Thu, Jun 07, 2012 at 07:32:45PM +0100, ex falso wrote: >> >> we always have to put the class restriction (TupleLength l) there, >> even though all possible type constructors of [*] have a TupleLength >> instance defined! > > Yes, and this is a feature, for at least two reasons. > > First: to the extent that Haskell's type system corresponds to a > logic, it corresponds to a constructive one. Types/propositions are > inhabited/proved by explicit terms/evidence. But this request (and > [1]) essentially boil down to a desire for double negation > elimination: if there *can't* *not* be a certain instance, then the > compiler should infer that there *is* one. This seems weird to me > (though perhaps I've just drunk too much of the constructivism > kool-aid). While I more or less agree with that (still not convinced completely)... > > Second, on a more practical level, the ability to omit class > constraints like this would make reasoning about types much more > non-local and difficult, since a type like > > foo :: Bar a -> Baz > > may or may not implicitly expand to something like > > foo :: SomeClass a => Bar a -> Baz ...this argument is irrelevant in my opinion. You will be forced by GHC type checking to specify which promoted type is an argument. So foo will have type "foo :: Bar (a :: Doh) -> Baz" and constraint will be "SomeClass (a :: Doh)". > (which could have important implications for things like inlining, > sharing, etc. -- cf the monomorphism restriction), but figuring out > whether it does or not requires knowing (a) the definition of Bar and > all the instances that are in scope, and (b) whether or not > SomeClass's methods ever get called from foo (or anything it calls, > recursively). I'd much rather explicitly write the SomeClass > constraint if I want it, and be guaranteed that it won't be added if I > don't. > > In summary, these constraints may be "superfluous" in a strictly > logical sense, but (a) not in the kind of logic that Haskell uses, and > (b) the pain and suffering caused by removing them would far outweigh > the tiny bit of typing that would be saved. I would like to suffer that removal. Bring the pain of it! Because right now there's no incentive to drop usual types and use the promoted ones. At least, in the concrete use case of type-level arithmetic (with variables, of course). > > -Brent > > [1] > http://haskell.1045720.n5.nabble.com/Data-Kinds-and-superfluous-in-my-opinion-constraints-contexts-td5689436.html > > ___ > 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] Large graphs
2012/5/20 Benjamin Ylvisaker : > I have a problem that I'm trying to use Haskell for, and I think I'm running > into scalability issues in FGL. However, I am quite new to practical > programming in Haskell, so it's possible that I have some other bone-headed > performance bug in my code. I tried looking around for concrete information > about the scalability of Haskell's graph libraries, but didn't find much. So > here are the characteristics of the problem I'm working on: > > - Large directed graphs. Mostly 10k-100k nodes, but some in the low 100ks. > - Sparse graphs. The number of edges is only 2-3x the number of nodes. > - Immutable structure, mutable labels. After initially reading in the > graphs, their shape doesn't change, but information "flows" around the graph, > changing the labels on nodes and edges. I would like to suggest to you a representation based in 32-bit integers as vertex index. I.e., "roll your own" Use strict IntMap IntSet for neighbor information, it is very efficient. > I wrote some code that reads in graphs and some some basic flow computations > on them. The first few graphs I tried were around 10k nodes, and the > performance was okay (on the order of several seconds). When I tried some > larger graphs (~100k), the memory consumption spiked into multiple GB, the > CPU utilization went down to single digit percentages and the overall running > time was closer to hours than seconds. Looks like your code does not force everything. It leaves some thunks unevaluated, check for that situation. It is common pitfall, not only for computations on graphs. > > Because the graph structure is basically immutable for my problem, I'm > tempted to write my own graph representation based on mutable arrays. Before > I embark on that, I wonder if anyone else can share their experience with > large graphs in Haskell? Is there a library (FGL or otherwise) that should > be able to scale up to the size of graph I'm interested in, if I write my > code correctly? The above structure (IntMap IntSet) allowed for fast computations on relatively large arrays, in order of 1M vertices and 16M undirected/32M directed edges. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Data Kinds and superfluous (in my opinion) constraints contexts
2012/5/17 Iavor Diatchki : > Hello, > > The context in your example serves an important purpose: it records the fact > that the behavior of the function may differ depending on which type it is > instantiated with. This is quite different from ordinary polymorphic > functions, such as `const` for example, which work in exactly the same way, > no matter how you instantiate them. Note that it doesn't matter that we > can solve the constraint for all types of kind `D`---the constraint is there > because we can't solve it _uniformly_ for all types. Oh, it was of great matter to me. Because constraints like that get through type family expressions and make it hard to conceal state that should satisfy constraints on type family expressions over the type of the state. I can write something like that: data Combinator s a where Combinator :: Class (TypeFamExpr s) => ... -> Combinator s a And I cannot write something like that: data Combinator a where Combinator :: Class (TypeFamExpr s) => .mentions s.. -> Combinator a If my TypeFamExpr does have type variables, I get a wild type error messages that mentions partially computed TypeFamExpr as an argument to constraint. I can make more detailed example, if you wish. > > -Iavor > PS: As an aside, these two forms of polymorphism are sometimes called > "parametric" (when functions work in the same way for all types), and > "ad-hoc" (when the behavior depends on which type is being used). > > > > > On Sun, May 6, 2012 at 9:48 AM, Serguey Zefirov wrote: >> >> I decided to take a look at DataKinds extension, which became >> available in GHC 7.4. >> >> My main concerns is that I cannot close type classes for promoted data >> types. Even if I fix type class argument to a promoted type, the use >> of encoding function still requires specification of context. I >> consider this an omission of potentially very useful feature. >> >> Example is below. >> >> - >> {-# LANGUAGE TypeOperators, DataKinds, TemplateHaskell, TypeFamilies, >> UndecidableInstances #-} >> {-# LANGUAGE GADTs #-} >> >> -- a binary numbers. >> infixl 5 :* >> data D = >> D0 >> | D1 >> | D :* D >> deriving Show >> >> -- encoding for them. >> data EncD :: D -> * where >> EncD0 :: EncD D0 >> EncD1 :: EncD D1 >> EncDStar :: EncD (a :: D) -> EncD (b :: D) -> EncD (a :* b) >> >> -- decode of values. >> fromD :: D -> Int >> fromD D0 = 0 >> fromD D1 = 1 >> fromD (d :* d0) = fromD d * 2 + fromD d0 >> >> -- decode of encoded values. >> fromEncD :: EncD d -> Int >> fromEncD EncD0 = 0 >> fromEncD EncD1 = 1 >> fromEncD (EncDStar a b) = fromEncD a * 2 + fromEncD b >> >> -- constructing encoded values from type. >> -- I've closed possible kinds for class parameter (and GHC >> successfully compiles it). >> -- I fully expect an error if I will try to apply mkD to some type >> that is not D. >> -- (and, actually, GHC goes great lengths to prevent me from doing that) >> -- By extension of argument I expect GHC to stop requiring context >> with MkD a where >> -- I use mkD "constant function" and it is proven that a :: D. >> class MkD (a :: D) where >> mkD :: EncD a >> instance MkD D0 where >> mkD = EncD0 >> instance MkD D1 where >> mkD = EncD1 >> -- But I cannot omit context here... >> instance (MkD a, MkD b) => MkD (a :* b) where >> mkD = EncDStar mkD mkD >> >> data BV (size :: D) where >> BV :: EncD size -> Integer -> BV size >> >> bvSize :: BV (size :: D) -> Int >> bvSize (BV size _) = fromEncD size >> >> -- ...and here. >> -- This is bad, because this context will arise in other places, some of >> which >> -- are autogenerated and context for them is incomprehensible to human >> -- reader. >> -- (they are autogenerated precisely because of that - it is tedious >> and error prone >> -- to satisfy type checker.) >> fromIntgr :: Integer -> BV (size :: D) -- doesn't work, but desired. >> -- fromIntgr :: MkD size => Integer -> BV (size :: D) -- does work, >> but is not that useful. >> fromIntgr int = BV mkD int >> >> - >> >> ___ >> 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] Data Kinds and superfluous (in my opinion) constraints contexts
I decided to take a look at DataKinds extension, which became available in GHC 7.4. My main concerns is that I cannot close type classes for promoted data types. Even if I fix type class argument to a promoted type, the use of encoding function still requires specification of context. I consider this an omission of potentially very useful feature. Example is below. - {-# LANGUAGE TypeOperators, DataKinds, TemplateHaskell, TypeFamilies, UndecidableInstances #-} {-# LANGUAGE GADTs #-} -- a binary numbers. infixl 5 :* data D = D0 | D1 | D :* D deriving Show -- encoding for them. data EncD :: D -> * where EncD0 :: EncD D0 EncD1 :: EncD D1 EncDStar :: EncD (a :: D) -> EncD (b :: D) -> EncD (a :* b) -- decode of values. fromD :: D -> Int fromD D0 = 0 fromD D1 = 1 fromD (d :* d0) = fromD d * 2 + fromD d0 -- decode of encoded values. fromEncD :: EncD d -> Int fromEncD EncD0 = 0 fromEncD EncD1 = 1 fromEncD (EncDStar a b) = fromEncD a * 2 + fromEncD b -- constructing encoded values from type. -- I've closed possible kinds for class parameter (and GHC successfully compiles it). -- I fully expect an error if I will try to apply mkD to some type that is not D. -- (and, actually, GHC goes great lengths to prevent me from doing that) -- By extension of argument I expect GHC to stop requiring context with MkD a where -- I use mkD "constant function" and it is proven that a :: D. class MkD (a :: D) where mkD :: EncD a instance MkD D0 where mkD = EncD0 instance MkD D1 where mkD = EncD1 -- But I cannot omit context here... instance (MkD a, MkD b) => MkD (a :* b) where mkD = EncDStar mkD mkD data BV (size :: D) where BV :: EncD size -> Integer -> BV size bvSize :: BV (size :: D) -> Int bvSize (BV size _) = fromEncD size -- ...and here. -- This is bad, because this context will arise in other places, some of which -- are autogenerated and context for them is incomprehensible to human -- reader. -- (they are autogenerated precisely because of that - it is tedious and error prone -- to satisfy type checker.) fromIntgr :: Integer -> BV (size :: D) -- doesn't work, but desired. -- fromIntgr :: MkD size => Integer -> BV (size :: D) -- does work, but is not that useful. fromIntgr int = BV mkD int - ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Data.IntMap union complexity
2012/2/24 Clark Gaebel : > Since insertion [2] is O(min(n, W)) [ where W is the number of bits in an > Int ], wouldn't it be more efficient to just fold 'insert' over one of the > lists for a complexity of O(m*min(n, W))? This would degrade into O(m) in > the worst case, as opposed to the current O(n+m). > > Or am I just crazy? This way you will create much more garbage, I think. The union of two completely disjoint maps can hold parts of them intact. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Composing analyses.
I am trying to create a stack of analyses. There are basic analyses then there are derived analyses that create a DAG of analyses. I thought I can express their relationship through type classes, but I failed. I've attached the source of my failure. Main points are below: getAnalysisResult :: EnabledAnalysis a as => a -> M as Int getAnalysisResult _ = error "getAnalysisResult!!!" setAnalysisResult :: EnabledAnalysis a as => a -> Int -> M as () setAnalysisResult _ _ = error "setAnalysisResult!!!" -- |Analysis interface. What to require and what to perform. class (Analyses (RequiresAnalyses a)) => Analysis a where -- |What has to be done before our pass. type RequiresAnalyses a -- |Perform an analysis. perform :: (EnabledAnalysis a as, EnabledAnalyses (RequiresAnalyses a) as) => a -> M as () data AnalysisNotEnabled a -- |Check if analysis is enabled. class EnabledAnalysis a as instance (FAIL (AnalysisNotEnabled a)) => EnabledAnalysis a Nil instance (Analysis a, Analyses as) => EnabledAnalysis a (a :. as) instance (Analysis a, Analysis a', EnabledAnalysis a as) => EnabledAnalysis a (a' :. as) -- |Check if a group of analyses is enabled. class EnabledAnalyses as eas instance EnabledAnalyses Nil eas instance (EnabledAnalyses as eas, EnabledAnalysis a eas) => EnabledAnalyses (a :. as) eas -- Base analysis. data Base = Base instance Analysis Base where type RequiresAnalyses Base = Nil perform a = do x <- getAnalysisResult a setAnalysisResult a (x+1) -- And analysis derived from Base. data Derived = Derived instance Analysis Derived where type RequiresAnalyses Derived = Base :. Nil -- !!! this is the source of problems -- the type here is -- (EnabledAnalysis Derived as, EnabledAnalyses (Base :. Nil) as) => -- Derived -> M as () -- Looks like ghc does not expand RequiresAnalyses Derived. perform a = do x <- getAnalysisResult a y <- getAnalysisResult Base setAnalysisResult a (x+y) -- here I expanded RequiresAnalysis Derived manually. -- ghc thinks that "EnabledAnalyses (Base :. Nil) as" does not imply "EnableAnalysis Base as". -- it is weird. performDerived :: (EnabledAnalysis Derived as, EnabledAnalyses (Base :. Nil) as) => Derived -> M as () performDerived a = do x <- getAnalysisResult a y <- getAnalysisResult Base setAnalysisResult a (x+y) This is behavior of ghc 6.12.1, 7.0.4 and 7.2.1. Is it right behavior? The main question is: is it possible to combine computations like this? How should one do this? I thinking about abandoning type classes altogether. I think I can do it some other way. But out of curiosity - why is that? a.hs Description: Binary data ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Hardware description in Haskell.
2011/12/11 Felipe Almeida Lessa : > On Sun, Dec 11, 2011 at 10:52 AM, Serguey Zefirov wrote: >> scrutiny and critique by Haskell users who is into hardware >> description. > A two years-old project is more than ready to be on Hackage. It will > sure make it easier to use by prospective users. This is two-years-long project, not two-years-old. It is only days old, it became useful this day, actually. I have two points in my TODO list. When I finish them I'll do a package. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Hardware description in Haskell.
I would like to introduce my over-than-two years long project, HHDL: http://thesz.mskhug.ru/svn/hhdl/hackage/hhdl/ (I prefer to pronounce it as a ha-ha-dee-el, this way it is more fun) It allows one to create digital hardware description in Haskell and then generate VHDL code (Verilog is on the way). Okay, it would allow one to do all that some day. I hope it will come sooner than later. I try to make all wires as typed as I can and to support algebraic types with patetrn matching. I wrote a simple example to demonstrate some of those facilities: http://thesz.mskhug.ru/svn/hhdl/hackage/hhdl/src/Hardware/HHDL/Examples/RunningSumMaybes.hs This is a simple accumulator that accepts a Maybe Word8 input. The resulting VHDL is very wordy, but looks superficially correct. I wrote two posts about HHDL: http://thesz.livejournal.com/1284055.html - slightly outdated as HHDL now generates VHDL that typechecks and allows one to name inputs and outputs http://thesz.livejournal.com/1284541.html - motivation behind HHDL There is no package for Hackage, because I do not feel HHDL is worth it right now. For example, I tested it on ghc 6.12.1, not later versions, the library code is messy. But HHDL is good enough for some scrutiny and critique by Haskell users who is into hardware description. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Disjunctive patterns
2011/12/8 Asger Feldthaus : > Haskell doesn't seem to support disjunctive patterns, and I'm having a > difficult time writing good Haskell code in situations that would otherwise > call for that type of pattern. > > Suppose for an example I have this data type: > > data T = Foo Int | Bar Int | Baz > > In OCaml I can write something like: > > (* foo : T -> T -> int *) > fun foo x y = match (x,y) with > | (Foo a | Bar a, Foo b | Bar b) -> a + b I solve that kind of problem by introducing operation enumerations. I can write expression definition like that: data Expr = Plus Int Int | Minus Int Int | Mul Int Int | Neg Int | Inv Int | Var String And then I will have exactly your problem. I prefer to write such definition like that: data Expr = Bin BinOp Int Int | Un UnOp Int | Var String data BinOp = Plus | Minus | Mul data UnOp = Neg | Inv And I have to write less code in all subsequent constructions and pattern matches. This is especially good when I used that method for an expression with result size: data Expr size where Bin :: BinOp xSize ySize resultSize -> Expr xSize -> Expr ySize -> Expr resultSize data BinOp a b r where Plus :: BinOp a a a Concatenate :: BinOp a b (Plus a b) Equal :: BinOp a a ONE ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] arr considered harmful
2011/11/1 Ryan Ingram : > For example, I would love to be able to use the arrow syntax to define > objects of this type: > > data Circuit a b where > Const :: Bool -> Circuit () Bool > Wire :: Circuit a a > Delay :: Circuit a a > And :: Circuit (Bool,Bool) Bool > Or :: Circuit (Bool,Bool) Bool > Not :: Circuit Bool Bool > Then :: Circuit a b -> Circuit b c -> Circuit a c > Pair :: Circuit a c -> Circuit b d -> Circuit (a,b) (c,d) > First :: Circuit a b -> Circuit (a,c) (b,c) > Swap :: Circuit (a,b) (b,a) > AssocL :: Circuit ((a,b),c) (a,(b,c)) > AssocR :: Circuit (a,(b,c)) ((a,b),c) > Loop :: Circuit (a,b) (a,c) -> Circuit b c > etc. > Would you mind give me some examples on how you desribe real circuits with that abstraction and, especially, an Arrow instance (even imaginary one)? I am interested because I thought about an approach like that and found it not easy to use one. So I stuck with monadic netlists. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Function code generation (Template Haskell).
The task is that I have some function and I need to create another function alongside with it. The second function is based on first one. As a matter of fact, I already did this with Template Haskell. TH is quite good at that task, because I can load my module in ghci and have both functions available for experiments. I just wondering, is it possible to use newly introduced ghc plugins to do something like that? Could I create new functions while inspecting defined ones? Will they be visible in ghci? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Simple GADTs, type families and type classes combination with type error.
2011/7/22 Felipe Almeida Lessa : > On Fri, Jul 22, 2011 at 12:12 PM, Serguey Zefirov wrote: >> Why does GHC complains on the code below ? (I'll explain in a second a >> requirement to do just so) > > I don't why =(. But you can workaround by using > > class CPU cpu where > data CPUFunc cpu > Thank you very much. I completely forgot that. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Simple GADTs, type families and type classes combination with type error.
2011/7/22 Dan Doel : > On Fri, Jul 22, 2011 at 11:12 AM, Serguey Zefirov wrote: > GHC cannot decide what instance of FuncVars to use. The signature of > funcVars is: > funcVars :: FuncVars cpu => CPUFunc cpu -> [String] > > This does not take any arguments that allow cpu to be determined. For > instance, if there were instances (rolling them into one declaration > for simplicity): > > instance FuncVars Int where > type CPUFunc Int = Int > ... > > instance FuncVars Char where > type CPUFunc Char = Int > > Then GHC would see that CPUFunc cpu = Int, but from this, it cannot > determine whether cpu = Int or cpu = Char. CPUFunc is not > (necessarily) injective. But "cpu" variable is the same in all places. If we don't dive into CPUFunc reduction (to Int or whatever) we can safely match funcVars argument and unify cpu. This is the case when we write generic functions over type family application. > Also, if you have a class whose only content is an associated type, > there's really no need for the class at all. It desugars into: > > type family CPUFunc a :: * > > class CPU a It would be somewhat inconvenient. I omitted some constraints in CPU class for the sake of presentation. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Simple GADTs, type families and type classes combination with type error.
Why does GHC complains on the code below ? (I'll explain in a second a requirement to do just so) I get errors with ghc 6.12.1 and 7.0.2. - {-# LANGUAGE GADTs, TypeFamilies #-} class CPU cpu where type CPUFunc cpu data Expr cpu where EVar :: String -> Expr cpu EFunc :: CPU cpu => CPUFunc cpu -> Expr cpu class CPU cpu => FuncVars cpu where funcVars :: CPUFunc cpu -> [String] exprVars :: FuncVars cpu => Expr cpu -> [String] exprVars (EVar v) = [v] -- an offending line: exprVars (EFunc f) = funcVars f - I tried to split creation and analysis constraints. CPU required for creation of expressions, FuncVars required for analysis. It all looks nice but didn't work. (In our real code EVar is slightly more complicated, featuring "Var cpu" argument) It looks like GHC cannot relate parameters "inside" and "outside" of GADT constructor. Not that I hesitate to add a method to a CPU class, but I think it is not the right thing to do. So if I can split my task into two classes, I will feel better. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Probably type checker error.
Thank you very much. I'll try that too. 2011/6/20 David Menendez : > GHC 6.12 introduces MonoLocalBinds, which disables polymorphic values > in let statements. > > Your original code works for me if I use -XNoMonoLocalBinds > -XNoMonomorphismRestriction. > > On Mon, Jun 20, 2011 at 9:02 AM, Serguey Zefirov wrote: >> The fact is that (Num a) context works and (ToWires a, Num a) context >> doesn't. At least in 6.12.1. >> >> This still looks to me like a bug. >> >> 2011/6/19 Miguel Mitrofanov : >>> Seems like let-generalization is at work here. >>> >>> Types of all values in the "where" section are inferred basically as if >>> they are declared at the top level. Therefore, inheritance fails without >>> NoMonomorphismRestriction. >>> >>> There is a proposal (from Big Simon) to remove let-generalization: >>> http://research.microsoft.com/en-us/um/people/simonpj/papers/constraints/let-gen.pdf >>> >>> On 19 Jun 2011, at 18:26, Serguey Zefirov wrote: >>> >>>> Right now I write a quite heavy transformation of Haskell source code >>>> and found some strange behaviour of typechecker. >>>> >>>> Some prerequisites: >>>> -- dummy class. My own class is much bigger, but I >>>> -- could reproduce that behaviour with that class. >>>> class ToWires a >>>> >>>> -- a type with phantom type arguments. >>>> data E ins outs = E >>>> >>>> -- a function that relates E and its inputs. >>>> projectInsType :: E ins outs -> ins >>>> projectInsType = error "projectInsType gets evaluated." >>>> >>>> -- "register" function. >>>> register :: a -> a -> a >>>> register def a = def >>>> >>>> -- a simple addition. >>>> add2 :: (ToWires a, Num a) => (a,a) -> a >>>> add2 (a,b) = a+b >>>> >>>> >>>> First I have a function: >>>> func :: (ToWires a, Num a) => Maybe a -> a >>>> func mbA = currentSum >>>> where >>>> x = case mbA of >>>> Just a -> a >>>> Nothing -> 0 >>>> nextSum = add2 (x,currentSum) >>>> currentSum = register 0 nextSum >>>> >>>> It typechecks and works just fine after some transformation. >>>> >>>> The transformation I work on transform code into something like that: >>>> func_E :: (ToWires a, Num a) => E (Maybe a) a >>>> func_E = r >>>> where >>>> r = E >>>> -- here we relate mbA and r. >>>> mbA = projectInsType r >>>> x = case mbA of >>>> Just a -> a >>>> Nothing -> 0 >>>> nextSum = add2 (x,currentSum) >>>> currentSum = register 0 nextSum >>>> >>>> Note the absence of input of func in transformed func_E. I relate mbA >>>> with it's proper type using binding "mbA = projectInsType r". >>>> >>>> Then suddently ghc loses all of the context associated with mbA. And >>>> find type error at the calling of add2. >>>> >>>> If I drop ToWires from contexts of func_E and add2 types, all works >>>> fine. If I change add2 to simple addition (x + currentSum), all works >>>> fine. >>>> >>>> Full source code is in attachment. >>>> >>>> I found it using ghc 6.12.1. I asked colleagues, they told me that the >>>> same error manifests itself in ghc 7.0.3. >>>> >>>> Should I fill a bug report or maybe I misunderstood something? >>>> ___ >>>> 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 >> > > > > -- > Dave Menendez > <http://www.eyrie.org/~zednenem/> > ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Probably type checker error.
The fact is that (Num a) context works and (ToWires a, Num a) context doesn't. At least in 6.12.1. This still looks to me like a bug. 2011/6/19 Miguel Mitrofanov : > Seems like let-generalization is at work here. > > Types of all values in the "where" section are inferred basically as if they > are declared at the top level. Therefore, inheritance fails without > NoMonomorphismRestriction. > > There is a proposal (from Big Simon) to remove let-generalization: > http://research.microsoft.com/en-us/um/people/simonpj/papers/constraints/let-gen.pdf > > On 19 Jun 2011, at 18:26, Serguey Zefirov wrote: > >> Right now I write a quite heavy transformation of Haskell source code >> and found some strange behaviour of typechecker. >> >> Some prerequisites: >> -- dummy class. My own class is much bigger, but I >> -- could reproduce that behaviour with that class. >> class ToWires a >> >> -- a type with phantom type arguments. >> data E ins outs = E >> >> -- a function that relates E and its inputs. >> projectInsType :: E ins outs -> ins >> projectInsType = error "projectInsType gets evaluated." >> >> -- "register" function. >> register :: a -> a -> a >> register def a = def >> >> -- a simple addition. >> add2 :: (ToWires a, Num a) => (a,a) -> a >> add2 (a,b) = a+b >> >> >> First I have a function: >> func :: (ToWires a, Num a) => Maybe a -> a >> func mbA = currentSum >> where >> x = case mbA of >> Just a -> a >> Nothing -> 0 >> nextSum = add2 (x,currentSum) >> currentSum = register 0 nextSum >> >> It typechecks and works just fine after some transformation. >> >> The transformation I work on transform code into something like that: >> func_E :: (ToWires a, Num a) => E (Maybe a) a >> func_E = r >> where >> r = E >> -- here we relate mbA and r. >> mbA = projectInsType r >> x = case mbA of >> Just a -> a >> Nothing -> 0 >> nextSum = add2 (x,currentSum) >> currentSum = register 0 nextSum >> >> Note the absence of input of func in transformed func_E. I relate mbA >> with it's proper type using binding "mbA = projectInsType r". >> >> Then suddently ghc loses all of the context associated with mbA. And >> find type error at the calling of add2. >> >> If I drop ToWires from contexts of func_E and add2 types, all works >> fine. If I change add2 to simple addition (x + currentSum), all works >> fine. >> >> Full source code is in attachment. >> >> I found it using ghc 6.12.1. I asked colleagues, they told me that the >> same error manifests itself in ghc 7.0.3. >> >> Should I fill a bug report or maybe I misunderstood something? >> ___ >> 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] Probably type checker error.
Cool. It works. Thank you very much! 2011/6/19 Miguel Mitrofanov : > Seems like let-generalization is at work here. > > Types of all values in the "where" section are inferred basically as if they > are declared at the top level. Therefore, inheritance fails without > NoMonomorphismRestriction. > > There is a proposal (from Big Simon) to remove let-generalization: > http://research.microsoft.com/en-us/um/people/simonpj/papers/constraints/let-gen.pdf > > On 19 Jun 2011, at 18:26, Serguey Zefirov wrote: > >> Right now I write a quite heavy transformation of Haskell source code >> and found some strange behaviour of typechecker. >> >> Some prerequisites: >> -- dummy class. My own class is much bigger, but I >> -- could reproduce that behaviour with that class. >> class ToWires a >> >> -- a type with phantom type arguments. >> data E ins outs = E >> >> -- a function that relates E and its inputs. >> projectInsType :: E ins outs -> ins >> projectInsType = error "projectInsType gets evaluated." >> >> -- "register" function. >> register :: a -> a -> a >> register def a = def >> >> -- a simple addition. >> add2 :: (ToWires a, Num a) => (a,a) -> a >> add2 (a,b) = a+b >> >> >> First I have a function: >> func :: (ToWires a, Num a) => Maybe a -> a >> func mbA = currentSum >> where >> x = case mbA of >> Just a -> a >> Nothing -> 0 >> nextSum = add2 (x,currentSum) >> currentSum = register 0 nextSum >> >> It typechecks and works just fine after some transformation. >> >> The transformation I work on transform code into something like that: >> func_E :: (ToWires a, Num a) => E (Maybe a) a >> func_E = r >> where >> r = E >> -- here we relate mbA and r. >> mbA = projectInsType r >> x = case mbA of >> Just a -> a >> Nothing -> 0 >> nextSum = add2 (x,currentSum) >> currentSum = register 0 nextSum >> >> Note the absence of input of func in transformed func_E. I relate mbA >> with it's proper type using binding "mbA = projectInsType r". >> >> Then suddently ghc loses all of the context associated with mbA. And >> find type error at the calling of add2. >> >> If I drop ToWires from contexts of func_E and add2 types, all works >> fine. If I change add2 to simple addition (x + currentSum), all works >> fine. >> >> Full source code is in attachment. >> >> I found it using ghc 6.12.1. I asked colleagues, they told me that the >> same error manifests itself in ghc 7.0.3. >> >> Should I fill a bug report or maybe I misunderstood something? >> ___ >> 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] Probably type checker error.
Right now I write a quite heavy transformation of Haskell source code and found some strange behaviour of typechecker. Some prerequisites: -- dummy class. My own class is much bigger, but I -- could reproduce that behaviour with that class. class ToWires a -- a type with phantom type arguments. data E ins outs = E -- a function that relates E and its inputs. projectInsType :: E ins outs -> ins projectInsType = error "projectInsType gets evaluated." -- "register" function. register :: a -> a -> a register def a = def -- a simple addition. add2 :: (ToWires a, Num a) => (a,a) -> a add2 (a,b) = a+b First I have a function: func :: (ToWires a, Num a) => Maybe a -> a func mbA = currentSum where x = case mbA of Just a -> a Nothing -> 0 nextSum = add2 (x,currentSum) currentSum = register 0 nextSum It typechecks and works just fine after some transformation. The transformation I work on transform code into something like that: func_E :: (ToWires a, Num a) => E (Maybe a) a func_E = r where r = E -- here we relate mbA and r. mbA = projectInsType r x = case mbA of Just a -> a Nothing -> 0 nextSum = add2 (x,currentSum) currentSum = register 0 nextSum Note the absence of input of func in transformed func_E. I relate mbA with it's proper type using binding "mbA = projectInsType r". Then suddently ghc loses all of the context associated with mbA. And find type error at the calling of add2. If I drop ToWires from contexts of func_E and add2 types, all works fine. If I change add2 to simple addition (x + currentSum), all works fine. Full source code is in attachment. I found it using ghc 6.12.1. I asked colleagues, they told me that the same error manifests itself in ghc 7.0.3. Should I fill a bug report or maybe I misunderstood something? a.hs Description: Binary data ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Comment Syntax
2011/6/3 Guy : > I wasn't proposing additional comment symbols; I'm proposing that anything > beginning with -- is a comment. I use --> as a infix operator to describe types in Template Haskell. So I too oppose your proposal. ;) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Decimal type-level arithmetic.
2011/6/1 Henning Thielemann : > > On Wed, 1 Jun 2011, Serguey Zefirov wrote: >> I would like to present my version of type arithmetic with decimal >> encoding: http://thesz.mskhug.ru/svn/hhdl/TyleA.hs > How does it compare to > http://hackage.haskell.org/package/type-level > ? My version is slightly simpler to use, I think, because type-level uses functional dependencies: "Type-level functions are implemented using functional dependencies of multi parameter type classes." I use type families. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Decimal type-level arithmetic.
I would like to present my version of type arithmetic with decimal encoding: http://thesz.mskhug.ru/svn/hhdl/TyleA.hs It is not worth Cabal package in its current state, but I hope it would be useful for someone. It is easy to use, just say Plus (D1 :. D2 :. D0) D8 to get a type of 128. Or you can say $(tySize 128) if you're not afraid to use Template Haskell. I tested it on my current project, it works quite well with numbers around 128..512, about 10-20 times faster than Peano numbers. As operations over this representation are not lazy (Peano numbers oeprations are lazy for one argument of Plus and for part of one argument of Max), it is not well suited for big number of operations done at once. I encountered it when I autogenerated a big arithmetic expression for big polymorphic data type. I think it is quite rare situation. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Erlang's module discussion
2011/5/28 Alex Kropivny : > Erlang has the advantage of functions being the basic, composeable building > block. Packages and modules are merely means to organize them, and mediocre > means at that, so a better system is definitely a possibility. Haskell has > the complication of having type definitions in addition to functions. Those "complicating" type definitions is *the* metadata Joe talking about. Or, at least, most valuable part of metadata, with package name (defines the author) and module path (defines high-level intent and less relevant parts of metadata). ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] The Lisp Curse
2011/5/19 Vo Minh Thu : > 2011/5/19 Andrew Coppin : >> http://www.winestockwebdesign.com/Essays/Lisp_Curse.html >> >> Some of you might have seen this. Here's the short version: >> >> Lisp is so powerful that it discourages reuse. Why search for and reuse an >> existing implementation, when it's so trivially easy to reimplement exactly >> what you want yourself? The net result is a maze of incompatible libraries >> which each solve a different 80% of the same problem. >> >> To all the people who look at Hackage, see that there are 6 different >> libraries for processing Unicode text files, and claim that this is somehow >> a *good* thing, I offer the above essay as a counter-example. > > So what exactly is the problem on hackage and what do you propose as a > solution? The problem is that you have to try several packages before you get to the stable point. The solution... I think that some ratings, like "used directly by ### packages/projects and indirectly by ###" would be nice, but not much. As for me, I like the diversity of packages. They attack close problems from different fronts. They express different ideas and views. I like all that. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] The Lisp Curse
I think this is much less applicable to Haskell than to Lisp. I think that most of intra-incompatibilities of Lisp stem from side effects. The rest is mostly due to (relatively) weak type system which let some errors slip. And remaining percent or two can be attributed to the power of Lisp. ;) 2011/5/19 Andrew Coppin : > http://www.winestockwebdesign.com/Essays/Lisp_Curse.html > > Some of you might have seen this. Here's the short version: > > Lisp is so powerful that it discourages reuse. Why search for and reuse an > existing implementation, when it's so trivially easy to reimplement exactly > what you want yourself? The net result is a maze of incompatible libraries > which each solve a different 80% of the same problem. > > To all the people who look at Hackage, see that there are 6 different > libraries for processing Unicode text files, and claim that this is somehow > a *good* thing, I offer the above essay as a counter-example. > > ___ > 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 to generate source code from TH Exp?
Just pretty-print a Exp. It seems that "show $ ppr exp" will produce exactly what you need. The same goes for Dec (declarations), etc. 2011/5/12 Stefan Kersten : > hi, > > i was wondering if it's possible to directly generate Haskell source code > from a Template Haskell `Q Exp', i.e. use TH as a kind of preprocessor? i am > asking because currently the iOS port of ghc doesn't support TH and i need > to generate some instances for the persistent package [1,2]. > > i've been toying with > > fmap ppr . runQ $ q > > but the result needs to be edited by hand quite a bit. any ideas where to > start? > > thanks, > > > [1] http://hackage.haskell.org/package/persistent > [2] http://hackage.haskell.org/package/persistent-template > > ___ > 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] Template Haskell reified type.
I turned out that it is in ghc 6.12. The same code in ghc 7.0.1 works just fine, Reification produces TupleT and ListT. I just rechecked it. I forgot that I use 6.12. Sorry about that. 2011/5/10 Simon Peyton-Jones : > Can you give a concrete example? There is code in GHC that is supposed to > produce TupleT and ListT! > > Simon > > | -Original Message- > | From: haskell-cafe-boun...@haskell.org > [mailto:haskell-cafe-boun...@haskell.org] On > | Behalf Of Serguey Zefirov > | Sent: 09 May 2011 14:43 > | To: haskell > | Subject: [Haskell-cafe] Template Haskell reified type. > | > | Language.Haskell.TH.Type contains, among others, two constructors: > | TupleT Int and ListT. > | > | I can safely construct types using them, but reification returns ConT > | "GHC.Tuple.(,)" and ConT "GHC.Types.[]" respectively. > | > | This is not fair asymmetry, I think. > | > | Also, it took purity from one of my functions while I debugged that > | problem. I had to make it into Q monad. ;) > | > | ___ > | 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] Using Haskell to describe computer hardware.
http://thesz.mskhug.ru/svn/hhdl/ - main repository and http://thesz.mskhug.ru/svn/hhdl/examples/Simple.hs - three simple examples and http://thesz.mskhug.ru/svn/hhdl/MIPS-example/ - an attempt to describe MIPS-alike CPU using Haskell. Not yet done, it passes only simplest of tests (it fetches commands), but if you take a look at it you'll get an idea of what is going on. The goal is to create something along the lines of Bluespec, but as a DSeL in Haskell. Right now I concentrate on single-clock circuits, as they comprise most of hardware logic. I hacked together transformation of not-so-complex Haskell function definition into Haskell functions that operate on infinite streams. Of course, I tried my best to support calling other functions, conditional operators, pattern matching, etc, because that's what makes Haskell great and Bluespec has them too. Below is little explanation of three simple examples. First comes very simple function: $(transform [d| f1 :: (ToWires a, Num a) => (a,a) -> a f1 (a,b) = a + b |]) After $(transform ...) you will have two functions: f1 and f1_S, the second one operates on streams. ToWires class in the context ensure that input and output values can be converted into arrays of bits when we'll get that part ready. The type of f1_S is: *Simple> :t f1_S f1_S :: (ToWires a[a9GC], Num a[a9GC]) => (S a[a9GC], S a[a9GC]) -> (S a[a9GC], S [String]) or put simply: *Simple> :t f1_S f1_S :: (ToWires a, Num a) => (S a, S a) -> (S a, S [String]) It accepts two streams and return two streams - value and logs. We could add messages into logs: $(transform [d| f2 :: (ToWires a, Num a) => (a,a) -> a f2 (a,b) = s where s = a + b _display_a = a _display_b = b _display_s = s |]) f2 is just like f1, but when ran, it will produce logs about execution along the values. f2 used by runningSum, which compute a sum of values seen before current cycle: $(transform [d| runningSum :: (ToWires a, Num a) => a -> a runningSum x = currentSum where nextSum = f2 (x,currentSum) currentSum = register 0 nextSum _display_currentSum = currentSum _display_x = x _display_nextSum = nextSum |]) runningSum uses latches. It latches nextSum to pass the value to the next cycle using "register" function. "register" accepts default value and a value to latch (stream of values to delay) . When the time will come for synthesizing circuits, our register's will become actual latches with reset and clk wires. This is how we test our runningSum_S with simple data: runningSumLogs :: IO () runningSumLogs = do mapM putStrLn $ map unlines $ take 5 $ toList_S $ snd $ runningSum_S (fromList_S [1::Int ..]) return () The output will be like the following: currentSum: 0 x: 1 nextSum: 1 nextSum_0 = Simple.f2 (x_1, currentSum_2): a: 1 b: 0 s: 1 currentSum: 1 x: 2 nextSum: 3 nextSum_0 = Simple.f2 (x_1, currentSum_2): a: 2 b: 1 s: 3 currentSum: 3 x: 3 nextSum: 6 nextSum_0 = Simple.f2 (x_1, currentSum_2): a: 3 b: 3 s: 6 Logs are nested and after label "nextSum_0 = Simple.f2 (x_1, currentSum_2):" we see logs from f2_S function. The code is in QUITE EXPERIMENTAL stage, but feel free to play and comment. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Template Haskell reified type.
Language.Haskell.TH.Type contains, among others, two constructors: TupleT Int and ListT. I can safely construct types using them, but reification returns ConT "GHC.Tuple.(,)" and ConT "GHC.Types.[]" respectively. This is not fair asymmetry, I think. Also, it took purity from one of my functions while I debugged that problem. I had to make it into Q monad. ;) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Python is lazier than Haskell
2011/4/27 Ketil Malde : > Henning Thielemann writes: > That "Haskell is great because of its laziness" is arguable, see Robert > Harper's blog for all the arguing. (http://existentialtype.wordpress.com/) I think that author sin't quite right there. http://en.wikipedia.org/wiki/Haskell_%28programming_language%29 Haskell (pronounced /ˈhæskəl/) is a standardized, general-purpose purely functional programming language, with *non-strict* semantics and strong static typing. Haskell is great because of non-strictness. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Stacking data types
I think I should suggest HList from Oleg Kiseliov. http://hackage.haskell.org/package/HList That way you will have something along those lines: -- fields descriptors: data Character data Gun data Armor data Life -- values for fields: data Vulcan = Vulcan { vulcanAmmoCount :: Int} data Player = Player { playerName :: String } player = (Character, Player) :*: (Gun,Vulcan) :*: (Armor,50) :*: HNil HList has all the machinery to create records, get a field from record (something like "getField rec Character"), test for field in record (Maybe value), etc. 2011/4/6 Yves Parès : > Hello Café, > > I'm trying to get some modular data types. > The idea that came to me is that I could stack them, for instance : > > data Character a = Character { life :: Int, > charaInner :: a } > > data Gun a = Gun { firepower :: Int, > gunInner :: a } > > data Armor a = Armor { resistance :: Int, > armorInner :: a } > > Then a character with a gun and an armor can be build this way: > > chara = Character 100 $ Armor 40 $ Gun 12 > > The idea now is to be able to get some part of the character: > > itsGun :: Character ?? -> Gun ?? > itsGun = content > > Then content would be a class method: > > class Has b a where > content :: a -> b > > And it would be recursively defined so that: > > instance (Has c b, Has b a) => Has c a where > content = (content :: b -> c) . (content :: a -> b) > > Then itsGun would be more like: > > itsGun :: (Has Gun a) => a -> Gun ?? > itsGun = content > > But after some juggling with extensions (ScopedTypeVariables, > UndecidableInstances, IncoherentInstances...) I can't get it working. > > Has someone a simpler way to achieve modular types? > > ___ > 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] Regarding two platforms build error.
Haskell Platform 2010.1 with ghc 6.12.1 worked quite well. Problem solved. ;) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Two Haskell Platforms on single machine.
I had to use two Haskell Platforms at once in the Windows environment. We use Haskell Platform 2011.1 as our main build platform. It provide real benefits for code with GADTs so we ported most of our code there. Right now we cannot switch back or it would be quite a regress. We also have some heavy type level computation code in one of our programs so we have to use Haskell Platform 2010.2 with ghc 6.12.3 as 7.0.2 is quite slow at that. And now I have some strange error (it didn't appear when I used only one of Haskell platforms): -- ghc-6.12.3 -O2 -odir objs -hidir objs -stubdir objs -o CGen.exe -fcontext-stack=100 --make CGen.hs Linking CGen.exe ... realgcc.exe: USERNA: Invalid argument C:\PROGRA~1\HASKEL~1\201020~1.0\lib\..\mingw\bin\windres: "C:\PROGRA~1\HASKEL~1\ 201020~1.0\lib\..\mingw\bin\gcc exited with status 1 -- When I looked at the dump in hex, I encountered that "USERNA" string contains "USERNAM^H" byte sequence, actually. I cannot look at ghc -v5 as I get another error: -- Glasgow Haskell Compiler, Version 6.12.3, for Haskell 98, stage 2 booted by GHC version 6.10.4 Using binary package database: C:\PROGRA~1\HASKEL~1\201020~1.0\lib\package.conf.d\package.cache ... ... (I deleted much of the lines) ... Deleting: *** Deleting temp dirs: Deleting: : hPutChar: invalid argument (character is not in the code page) -- I use localized version of Windows XP so it appears that ghc cannot print some name with russian characters in it. And here I stuck. I cannot find source of one error because of another error. Could anyone help me? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Type System vs Test Driven Development
2011/1/6 Evan Laforge : >> QuickCheck especially is great because it automates this tedious work: >> it fuzzes out the input for you and you get to think in terms of >> higher-level invariants when testing your code. Since about six months >> ago with the introduction of JUnit XML support in test-framework, we >> also have plug-in instrumentation support with continuous integration >> tools like Hudson: > Incidentally, I've never been able to figure out how to use > QuickCheck. Maybe it has more to do with my particular app, but > QuickCheck seems to expect simple input data and simple properties > that should hold relating the input and output, and in my experience > that's almost never true. For instance, I want to ascertain that a > function is true for "compatible" signals and false for "incompatible" > ones, where the definition of compatible is quirky and complex. I can > make quickcheck generate lots of random signals, but to make sure the > "compatible" is right means reimplementing the "compatible" function. I should say that this reimplementation would be good. If you can compare two implementations (one in plain Haskell and second in declarative QuickCheck rules) you will be better that with only one. We did that when testing implementations of commands in CPU model. Our model was built to specification and we have to be sure we implement it right. One problem was in CPU flags setup, specification was defined in terms of bit manipulation, we wrote tests that did the same but with ordinary arithmetic. Like carry = (a+b) `shirtR` 8 was compared with carry = bit operandA 7 && bit operandB 7 && not (bit result 7). We found errors in our implementation, we fixed them and there was almost no errors found after that. Doing two implementation for testing purposes can be boldly likened to code review with only one person. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Type System vs Test Driven Development
2011/1/6 Arnaud Bailly : > I would supplement this excellent list of advices with an emphasis on > the first one: Test-Driven Development is *not* testing, TDD is a > *design* process. Like you said, it is a discipline of thought that > forces you first to express your intent with a test, second to write > the simplest thing that can possibly succeed, third to remove > duplication and refactor your code. Change T in TDD from Test to Type and you still get a valid description like "It is a discipline of thought that forces you first to express your intent with a type, second to write the simplest thing that can possibly succeed, third to remove duplication and refactor your code." As for me, I prefer testing in the largest possible. I write functions, experiment with them in REPL, combine them and check combination result in REPL and when I cannot specify experiment in one line of ghci, I write test. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] GHC.Paths (libDir)
I figured that out, thank you if you are writing answer. ;) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] GHC.Paths (libDir)
I am looking at GHC API examples page: http://www.haskell.org/haskellwiki/GHC/As_a_library One of examples use "import GHC.Paths ( libDir)" and mentions that it needs "-package ghc-paths" option. I tried the second example with latest Haskell Platform (Windows). I commented out libDir = "/usr..." as it is not applicable to my case and inserted GHC.Paths import. So I run it like "ghci -package ghc -package ghc-paths A.hs" and get an error that ": cannot satisfy -package ghc-paths". When I do not use -package ghc-paths, it fails to load a module "GHC.Paths". What should I do to obtain libDir? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Data.Typeable TypeRep Ord instance.
2010/12/30 Andreas Baldeau : > instance Ord TypeRep where > compare t1 t2 = > compare > (unsafePerformIO (typeRepKey t1)) > (unsafePerformIO (typeRepKey t2)) I think it would suffice. Thank you for a tip. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell Parse Tree
2010/12/21 Jane Ren : > Does anyone know how to get the parse tree of a piece of Haskell code? > Any recommended documentation? ghc as a library? http://www.haskell.org/haskellwiki/GHC/As_a_library ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] An Haskell implementation of a sweep line algorithm for the detection of segments intersection
2010/12/6 vince vegga : > Here is my Haskell implementation of the Shamos and Hoey algorithm for > detecting segments intersection in the plane: > > http://neonstorm242.blogspot.com/2010/12/sweep-line-algorithm-for-detection-of.html Quite good, actually. Myself, I rarely write code that is on par with yours. ;) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Data.Typeable TypeRep Ord instance.
2010/12/5 Tianyi Cui : > Why should they? You can compare them in whatever way you like. And there > isn't a natural/inherent sense of total order between types. I cannot compare then the way I'd like. ;) Consider the following: data BiMap a = BiMap { values :: Map Int a ,indices :: Map a Int } It will serve well for Int's, Bool's and Expr's. Then I decided to store typed Expr's, based on GADTs. Those Expr's contains type indices and it would be natural to classify BiMaps by their type indices and look up in there. If I require type indices to be Typeable, all I need is ordering on TypeRep. Also, I prototyped hypergraph library with hyperedges as types with type family as HList of types denoting labels. There I needed ordering on TypeRep too, again, for efficiency reasons. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Data.Typeable TypeRep Ord instance.
Why TypeRep does have equality and doesn't have ordering? It would be good to have that. Right now when I have to order two type representations I convert them to string and then compare. This is somewhat inefficient and not quite straightforward. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Reduceron: reduced to numbers.
2010/12/4 Henning Thielemann : > Serguey Zefirov schrieb: > >> Of course, Reduceron in ASIC will require some cache memory, some >> controllers, etc. So it won't be that small, like 230K transistors. >> But, mzke it 2.3M transistors and it still be 2 orders of magnitude >> less than Core2 Duo... ;) > Cool! Do you have plans how it can be used eventually? As expansion > card? As main processor? How to compile Haskell to Reduceron code? I don't know answers to most of your questions. But colleague of mine said that reduceron could be programmed into FPGA part of upcoming Atom E600 - the one with Altera FPGA nearby. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Digests
2010/12/4 Permjacov Evgeniy : >> near cryptographic) security. To quote Wikipedia again: "The avalanche >> effect is evident if, when an input is changed slightly (for example, >> flipping a single bit) the output changes significantly (e.g., half >> the output bits flip)." > This simply means, that active set of bits must be at least of the size > of final value and value to be added must be added somehow to every byte > in active set. The simplest way to do it is multiplication of vector > [active-state-bits++current-byte] and some matrix of size [resulting > bytes count|resulting bytes count + 1] (of cource, not in floating-point > math, but, for example, using modulo-256 arithmetic or even hand-coded > tables for "mul" and "sum"). This, of course, means, that byte-streaming > hashes needs some initial seed (that must be paired with resulting value > to check) and that every byte will cause much operations to perform, > resulting in poor performance. So, the conclusion is: byte-streaming > hashes are possible, but because of requirements definitly will have > poor performance, much worse then block ones. Am I correct? I think you are correct. PS The note about matrices is interesting one. The total matrix should be dense, but we could factor it. For example, by multiplying two N wide and M wide band matrices we will get (N+M) wide band matrix. You are free to choose multiplication and addition operations, like addition could be XOR and multiplication could be ROTATE_LEFT (like in RC5). I did a little experiment: http://thesz.mskhug.ru/svn/cryptomatrix/ Just to demonstrate interesting properties of your suggestion. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Digests
2010/12/3 Permjacov Evgeniy : >>> */me wrote it into to_read list. The problem is, however, that block >>> ciphers are quite unfriendly to plain word8 streams. It is not a deadly >>> problem, but i'd like to avoid block collections. >> All one-way hashes do block collections. This is unavoidable. > Why ? Is there some math behind this proposition ? This is hard - to add single byte into the sum with cryptographic (or near cryptographic) security. To quote Wikipedia again: "The avalanche effect is evident if, when an input is changed slightly (for example, flipping a single bit) the output changes significantly (e.g., half the output bits flip)." http://en.wikipedia.org/wiki/Avalanche_effect This is true for hashes too. Hash should change about half of the random output bits when single bit of input changes. Especially if you aim to tamper-proof hashes. You have to have that property on every round of hashing, because you don't know when to stop. For bytes, you have to guarantee that you get an avalanche effect for every byte - it means, that you have to transform your entire block plus input byte in an expensive way. MD5 and all other hashes have internal state of various size, they all keep input blocks to make hashing transform less expensive. Fast methods like sum-modulo-poly (CRC variants) or linear congruential generators do not have good avalanche property when used for stream hashing or encryption. Even their combination (one in ZIP encryption) wasn't strong enough. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Digests
2010/12/3 Permjacov Evgeniy : >> Most of the time you can get away with usual block ciphers (and even >> with weaker parameters). There is a scheme that transforms block >> cipher into hash function: >> http://en.wikipedia.org/wiki/CRHF#Hash_functions_based_on_block_ciphers > */me wrote it into to_read list. The problem is, however, that block > ciphers are quite unfriendly to plain word8 streams. It is not a deadly > problem, but i'd like to avoid block collections. All one-way hashes do block collections. This is unavoidable. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Digests
2010/12/3 Permjacov Evgeniy : > The data integrity checks is well-known problem. A common soluting is > use of 'checksums'. Most of them , however, are built in quite > obfuscated manner (like md5) that results in ugly and error-prone > implementations (see reference implementation for same md5). > > So, the question is: is there a checksum, that is easy to implement over > stream of bytes and may work as good checksum and is good in sence that > creation of messages with same checksum that given message has is very > hard problem (at least 2^128 tries) ? 2^128 tries needed for hash size of 256 bits. See http://en.wikipedia.org/wiki/Birthday_attack Most of the time you can get away with usual block ciphers (and even with weaker parameters). There is a scheme that transforms block cipher into hash function: http://en.wikipedia.org/wiki/CRHF#Hash_functions_based_on_block_ciphers RC5, for example, parametrized by number of encryption rounds. RC5 with 12 rounds has sufficiently good avalanche (spread of bit change) so that you can use 12-round RC-5 instead of full death proof 20-round. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Reduceron: reduced to numbers.
I decided to calculate Reduceron's number of transistors (I had to, we have some argument here;). Reduceron allocate 14% of 17300 slices of Virtex-5 FPGA. If we assume that each slice correspond to 8 4-input NAND-NOT elements, we will get 2 4-input NAND. Each 4-input NAND contains 8 transistors, so the count of logic transistors is about 16. Reduceron use 90% of 1.5Kbyte RAM blocks. Using 6 transistors per RAM bit, we get 66K transistors more. So Reduceron should contain about 230K transistors if someone decides to go ASIC. It's 3 orders of magnitude less than x86, on par with most late chips of Chuck Moore (inventor of Forth, MISC concept and the one who develops some strange chips in GreenArrays http://greenarraychips.com/ now). The difference between Reduceron and GA144 of Chuck Moore is that Reduceron could be programmed much more easily, and that rocks. Clock frequency of 96MHz should go up too. My experience suggest numbers between 5 and 8 times. So single Reduceron should be of equal performance to Core2 Duo, at least. PS Of course, Reduceron in ASIC will require some cache memory, some controllers, etc. So it won't be that small, like 230K transistors. But, mzke it 2.3M transistors and it still be 2 orders of magnitude less than Core2 Duo... ;) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Help me TH code.
2010/10/27 Andy Stewart : > Serguey Zefirov writes: >> I think that you should use TH properly, without compiler and logical errors. >> >> What actually do you want? > I'm build multi-processes communication program. You don't need TH here, I think. You can write a class Ask: class Ask a where ask :: YourMonad a and then instance it: instance Ask Int where ask = liftIO $ do { putStrLn "Enter integer:"; l <- getLine; return $ read l} instance Ask Char where ask = liftIO $ do { putStrLn "Enter char:"; l <- getLine; return $ head l} instance Ask String where ask = liftIO $ do { putStrLn "Enter string:"; l <- getLine; return l} instance (Ask a, Ask b, Ask c) => Ask (a,b,c) where ask = liftIO $ do { a <- ask; b <- ask; c <- ask; return (a,b,c)} You can pass ask values between processes, receiving results of asking. TH is great and good, but it is that only when you absolutely exhausted of usual Haskell options. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Help me TH code.
2010/10/27 Andy Stewart : > Hi all, > > I want use TH write some function like below: > > data DataType = StringT > | IntT > | CharT > > parse :: [(String,DataType)] -> (TypeA, TypeB, ... TypeN) > > Example: > > parse [("string", StringT), ("001", IntT), ("c", CharT)] > > will return: > > ("string", 001, 'c') > > So how to use TH write 'parse' function? I think that you should use TH properly, without compiler and logical errors. What actually do you want? I think that parse should have type (parse :: [(String, DataType)] -> Q Exp). I think that OverloadedStrings extension should serve you as well. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Packaging a Gtk2hs based program for Windows
2010/10/7 Dmitry V'yal : > It sounds: How to make a neat Windows installer for a nice Gtk2hs program I > wrote last week? How to solve the problem of dependency on GTK? Should I ask > my users to install a GTK package or it would be better to package all the > dynamic libraries needed along with my program? Are there any troubles with > different character encodings used in Windows? How to change the application > icon? And so on.. It is better to copy GTK libraries with your application. If you ask user to install GTK libraries they can install incompatible version (and certainly will). ;) We didn't encountered difficulties with different character encodings. You have to look on gcc documentation (ld part of it) where you can specify resource file with application icon. Don't forget -mwindows key for ld. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskellers.com profiles: advice requested
2010/10/6 Michael Snoyman : >>> * How granular should we get? For web programming, for instance, >>> should we ask about Yesod, Happstack, Snap, etc? >> >> I think that "skill cloud" would be nice so I can add my new skills >> (packages, programs, domain specific knowledge) as I acquire them (or >> write them). > > Could you describe what you mean by "skill cloud" here? I was more > focused right now on the skills available for selection versus the > manner of displaying them. Just let us haskellers to specify list of skills in comma-separated list. If someone enters a new skill, it should became visible only when some member of community provide links to information about them. That way I can say "C, VHDL, hardware modeling, dynamic dataflow sorting machine" and it would meand that I am proficient in C, VHDL, that I specialize in hardware modeling and that I wrote a model of dynamic dataflow CPU. >> If we provide some links associated with tags, it would be possible to >> classify skills according to their relevance to haskell community. > > Once again, I'm not quite sure what you mean here; could you clarify? Each tag will have associated links. Some from community, some from haskeller itself. That way someone can review tags and decide whether they relevant for Haskell community. For example, my dataflow sorting machine was implemented in Haskell, so it is relevant. My C, VHDL and hardware modeling skills aren't that relevant. That way it is up to community to decide the list of skills. It is up to selected members of community to decide their relevance. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskellers.com profiles: advice requested
2010/10/6 Michael Snoyman : > Hi all, > > After finally getting OpenID 2 support worked out, I've now put up the > Haskellers.com website[1]. Not all features are implemented yet, but > the basics are in. Would it be possible to be able to login or consolidate two (or more) different OpenID? For example, I would like to identify myself using GMail or Livejournal OpenID. > For now, I collect email address (spam-protected, don't worry), > website, number of years of Haskell experience, and a free-form > description. I've also added a skills section, but have purposely not > added many. I wanted community input on the kinds of skills. Some > ideas: > > * Web programming > * Compiler writing > * Write a monad tutorial :/ > > I see two main questions when it comes to selecting this list of skills: > > * How granular should we get? For web programming, for instance, > should we ask about Yesod, Happstack, Snap, etc? I think that "skill cloud" would be nice so I can add my new skills (packages, programs, domain specific knowledge) as I acquire them (or write them). > * Should we include non-Haskell skills. I can imagine that employers > would like to know that people also have experience with Java/C#/etc, > but on the other hand we might want to make this Haskell-specific. > > One recommendation (from my wife actually) is to have two separate > lists: a static list of Haskell-specific skills that users simply > checkmark off, and then "additional skills" that everyone makes up > themselves. If we provide some links associated with tags, it would be possible to classify skills according to their relevance to haskell community. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] I still cannot seem to get a GUI working under Windows.
2010/9/30 Andrew Coppin : > And even then, your > developed application will only run on Windows boxes that have GTK+ > installed (i.e., none of them). You can copy GTK+ DLLs with application. It works very well. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Relaxing atomicity of STM transactions
2010/9/29 Tom Hawkins : > In the embedded domain, this could be a fault monitor that > reads a bunch of constantly changing sensors. I think that sensor reading belongs to IO, not STM. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Help to create a function to calculate a n element moving average ??
2010/9/26 rgowka1 : > Type signature would be Int -> [Double] -> [(Double,Double)] > > Any thoughts or ideas on how to calculate a n-element moving average > of a list of Doubles? > > Let's say [1..10]::[Double] > > what is the function to calculate the average of the 3 elements? > > [(1,0),(2,0),(3,2),(4,3)] :: [(Double,Double)] > > (1,0) the average is zero as the length is less than 3 > > (2,0) the average is zero as the length is less than 3 > > (3,2) the average is (1+2+3)/3 = 2 > > (4,3) the average is (2+3+4)/3 = 9 movingAverage n xs = map (/n) $ sums n xs sums 1 xs = xs sums n xx@(x:xs) = zipWith (+) xx (sums (n-1) xs) Tests: *Main> movingAverage 1 [1..10] [1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0] *Main> movingAverage 2 [1..10] [1.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5,9.5] *Main> movingAverage 3 [1..10] [2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0] *Main> movingAverage 4 [1..10] [2.5,3.5,4.5,5.5,6.5,7.5,8.5] Is it right? ;) It is more interesting to create movingAverage in CPS/iteratees style. That way you'll have solid interface with IO world and you can freely alternate between reading moving averages and waiting for another ticket. No magic usafeInterleaveIO, hGetContents, etc, will be required. I did this once for my friend's pet project in Erlang, we jointly developed a whole library of operators over time series - sums, averages, etc. It is simple and fun. ;) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Scraping boilerplate deriving?
2010/9/14 Kevin Jardine : > I would like to use some macro system (perhaps Template Haskell?) to > reduce this to something like > > defObj MyType > > I've read through some Template Haskell documentation and examples, > but I find it intimidatingly hard to follow. Does anyone has some code > suggestions or pointers to something similar? The solutions first: - {-# LANGUAGE TemplateHaskell #-} module T(mkNewType) where import Language.Haskell.TH decls = [d|newtype TempDecl = TempDecl Int deriving (Eq,Ord,Show)|] decl = do [d] <- decls runIO $ print d -- just to show inetrnals return d mkNewType :: String -> Q [Dec] mkNewType n = do d <- decl let name = mkName n return $ (\x -> [x]) $ case d of (NewtypeD cxt _ argvars (NormalC _ args) derivings) -> NewtypeD cxt name argvars (NormalC name args) derivings -- I took perfectly valid declaration, dissected it using case analysis and changed relevant parts. And an example client: - {-# LANGUAGE TemplateHaskell #-} import T $(mkNewType "A") - It all work together. I studied how to use Template Haskell that way: I obtained declarations of what I need, printed them and looked through documentation for relevant data types and constructors. It's not harder that any other library in Haskell, actually. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Re[4]: [Haskell-cafe] overloaded list literals?
2010/9/6 Bulat Ziganshin : > Hello Serguey, > > Monday, September 6, 2010, 8:16:03 PM, you wrote: >> Basically, you - and others, - propose to add another class isomorphic >> to already present lists. I think, most benefits of that class can be >> achieved by using list conversion and RULE pragma. > what i propose should allow to convert algorithm dealing with strings > into algorithm dealing with ByteStrings, simply by changing import > statement View patterns?.. Also, I think that some general optimization that can fold computations together (like supercompilation) will certainly help here. > it's a cute goal - keep Haskell strings easy of use but add ByteString > performance Completely agree, this is a noble goal. But ByteStrings aren't polymorphic. So they cannot satisfy your class. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Re[2]: [Haskell-cafe] overloaded list literals?
2010/9/6 Bulat Ziganshin : > Hello Serguey, > Monday, September 6, 2010, 7:57:46 PM, you wrote: >>> http://www.mail-archive.com/haskell-cafe@haskell.org/msg15656.html >> Will Data.Map with its' empty, insert, findMin, etc, "methods" conform >> to your proposed type? > but Data.Map isn't sequential container. instead, it maps arbitrary > keys to values That situation reminds me situation with Set Monad instance. ;) Basically, you - and others, - propose to add another class isomorphic to already present lists. I think, most benefits of that class can be achieved by using list conversion and RULE pragma. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] overloaded list literals?
2010/9/6 Bulat Ziganshin : > Hello Johannes, > > Monday, September 6, 2010, 2:23:35 PM, you wrote: > >> so how about using list syntax ( [], : ) >> for anything list-like (e.g., Data.Sequence)? > > i'vwe found my own proposal of such type: > http://www.mail-archive.com/haskell-cafe@haskell.org/msg15656.html Will Data.Map with its' empty, insert, findMin, etc, "methods" conform to your proposed type? I don't think so and I thought twice. ;) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Haskell Platform on Windows - cabal update problems.
2010/9/5 Mikhail Glushenkov : > Try removing the 'Application Data/cabal' directory and running > 'cabal update'. You probably made a syntax error in the config > file. You are clearly a magician. ;) Now it works flawlessly. Thank you very much. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Haskell Platform on Windows - cabal update problems.
I've installed recent Haskell Platform and tried to wrap my head around cabal to finally figure out how to use it. First thing I bumped into is that cabal.exe does not know about any remote repositories, even about hackage. So after googling I found that I should add a line "remote-repo: hackage.haskell.org:http://hackage.haskell.org/packages/archive"; into my cabal config file. So I did. And now I have "cabal update" command trying to download packages list from hackage. To no avail. Now it gives me even more interesting error: "cabal.EXE: fromFlag NoFlag. Use fromFlagOrDefault" Googling doesn't help here. What does it mean and how to get rid of it? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Announce: lhae
2010/9/3 abau : > lhae is a spreadsheet program. It features a simple formula language and > some basic statistical methods, like descriptive statistics and pivot > tables. Interesting. You had selected wxWidgets because of what? Also, how long did it took (especially GUI part)? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Ordering TypeRep from Data.Typeable.
I think, that TypeRep type from Data.Typeable needs Ord class instance. It is unnecessary, but is handy when needed. My use case follows. I try to create graph whose node and arc labels are differently typed. So I can add Int node, Float node and link them by Conversion arc. Right now I am quite good with GADTs that hide values of different types. But when I thinking about querying that structure, I start to want ordered TypeRep. I then can collect different arcs and nodes into different sets and speed up query processing dramatically. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Fast Integer Input
2010/8/23 Bertram Felgenhauer : > Serguey Zefirov wrote: > The timings seem about right. Thank you for letting me know about divide-and-conquer variant. But I am still amuzed that producing 1200 words of data from 13Kbytes of text took those little 200 cycles of CPU. This is quite interesting and I think I should investigate that later. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Fast Integer Input
2010/8/23 <200901...@daiict.ac.in>: > This function takes 1.8 seconds to > convert 2000 integers of length 10^13000. I need it to be smaller that > 0.5 sec. Is it possible? 2000 integers of magnitude 10^13000 equals to about 26 MBytes of data (2000 numbers each 13000 digits long). Rounding 1.8 seconds to two seconds we conclude that you proceed with speed about 13MBytes per second. Assuming you have CPU clock frequency near 2.6GHz, you performing about 200 clock cycles per input digit. 10^13000 roughly equal to 2^39000. Or (2^32)^1219 - 1219 32-bit words of representation. So you're doing some last nextN = (n*10)+currentDigit conversion operations in less that one clock cycle per word. Either I err'd in my math, or you're performing better than most of us could expect. Maybe you are off in your 10^13000 by an order of magnitude. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Higher-order algorithms
2010/8/23 Eugene Kirpichov : > For example, parser combinators are not so interesting: they are a > bunch of relatively orthogonal (by their purpose) combinators, each of > which is by itself quite trivial, plus not-quite-higher-order > backtracking at the core. This is only if you're not quite considering generalizing parser combinators to non-backtracking algorithms. The CYK algorithm [1] does not backtrack, it merges partial parsing results. When I thought about it I figured that parser combinators became even more restricted that they in arrow parsers. [1] http://en.wikipedia.org/wiki/CYK_algorithm PS CYK is interesting because it provides parallel parsing opportunities, it can parse many parts of text in parallel and then merge bags of successful parsings into another successful parsings. As CYK does not care about start of sequence it was used to parse grammars on hypergraphs: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.47.6425 PPS I didn't thought fully about CYK parser combinators yet. But I think that CYK could be an example of something unusual in the accustomed field of parsing. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Support for lock-free/wait-free programming?
2010/8/17 Gregory Collins : > Does GHC expose any primitives for things like atomic compare-and-swap? I think that STM could qualify as LL/SC. It does LL with TVars and bulk SC with transaction commit. ;) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Is there any experience using Software Transactional Memory in substantial applications?
2010/8/8 Johnny Morrice : >> My opponent gave me that link: > http://logicaloptimizer.blogspot.com/2010/06/so-microsofts-experiments-with-software.html > > I enjoy the article you linked but I sort of skimmed it because it was a > little boring, however its main point seem to be: > > 1. Ghostbusters. > 2. Artificial intelligence is useless [1] > 3. Listen to Anders! [2] > > Anders Hejlsberg: Some would argue it's t h e > wrong way to look at the problem in the beginning. > We shouldn't have the shared state to begin with. > > Richard Campbell: Right. "Except that we have to write real apps" is a real gem of that conversation. ;) Thank you very much for your points. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Is there any experience using Software Transactional Memory in substantial applications?
Thank you very much. This is just the answer I needed. 2010/8/8 Alberto G. Corona : > > > -- Forwarded message -- > From: Alberto G. Corona > Date: 2010/8/8 > Subject: Re: [Haskell-cafe] Is there any experience using Software > Transactional Memory in substantial applications? > To: Serguey Zefirov > > > This first papers is the first that describes the preliminary haskell > implementation and the performance data says that STM scales well with the > number of CPU cores Blocking does not scale, as expected. > http://research.microsoft.com/en-us/um/people/simonpj/papers/stm/lock-free-flops06.pdf > In this other study, also for microsoft: > Dissecting Transactional Executions in Haskell. > The worst performance in the study is from an extreme case example form my > package TCache described here. In that example, a set of treads update the > same two objects all the time. Since STM is non blocking, all threads tries > to perform the task and rollback at the very end if things have been changed > by other thread in the meantime. Just like databases. The bad thing is that > the more CPU cores are executing the example, the more work being rolled > back is done. That is more or less the history. > I heard (The Monad Reader -mplementing STM in pure Haskell) about other > tentative implementation that do not wait for the end of the atomic task to > test the atomicity of the transaction, but instead, any update of a TVar > inmediately invalidates (and kill) all atomic transactions that uses that > TVar. This could potentially improve the performance a lot. > However I don´t know the strategy of the current haskell implementation nor > the strasategy of the Microsoft runtime(s) either. > Anyway, it is waranteed 100% that 1) the slowest in memory transaction is > way faster than the transaction delegated to the fastest external database. > 2) in memory transactions with blocking is a nightmare. For me these are > enough arguments for STM usage in many ordinary (I mean Web) applications. > > > 2010/8/8 Serguey Zefirov >> >> Recently we discussed Haskell and especially types in Russian part of >> LiveJournal and of course we talk about STM. >> >> My opponent gave me that link: >> >> http://logicaloptimizer.blogspot.com/2010/06/so-microsofts-experiments-with-software.html >> >> It says that performance with STM in Microsoft Research was more than >> horrible. >> >> I failed to find convincing counter-evidence on the web. Not for >> Haskell, even for Java/C#/C++. >> >> So I asking Haskell-cafe for clarification. Do anyone here have an >> experience with STM in computing-intensive tasks? Did it help there? >> What are the possible reasons for STM failure in MR? >> ___ >> 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
[Haskell-cafe] Is there any experience using Software Transactional Memory in substantial applications?
Recently we discussed Haskell and especially types in Russian part of LiveJournal and of course we talk about STM. My opponent gave me that link: http://logicaloptimizer.blogspot.com/2010/06/so-microsofts-experiments-with-software.html It says that performance with STM in Microsoft Research was more than horrible. I failed to find convincing counter-evidence on the web. Not for Haskell, even for Java/C#/C++. So I asking Haskell-cafe for clarification. Do anyone here have an experience with STM in computing-intensive tasks? Did it help there? What are the possible reasons for STM failure in MR? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Combining Gtk2hs and Fieldtrip
Gtk2hs has an OepnGL binding. So you can create OpenGL context and draw there. I don't think you will still be able to use parallel threads, but path to hardware renderer will be shorter for sure. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Microsoft's Singularity Project and Haskell
2010/7/31 David Leimbach : > Haskell's great and all but it does have a few warts when it comes to how > much real trust one should put into the type system. > Some compromises still exist like unsafePerformIO that you can't detect > simply by looking at the types of functions. Okay, you should look into modules' imports. This worked well for Ada (as far as I can remember - but I didn't program, i just read a book;) and wasn't concern back then and isn't now. > In order to live up to the hype and the marketing around Haskell, really > things like unsafePerformIO should not be allowed at all. You can use Haskell to generate quite safe code and that generator will use much of haskell type system while not suffering from unsafePerformIO. > The type of > unsafePerformIO $ fireTheMissles >> return 3 ::Int > is just Int after all. > Does Singularity also have such back doors? This is what new Microsoft OS Barrelfish does: http://www.barrelfish.org/fof_plos09.pdf ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Type Families: deleting from HList.
Is it possible to delete an element from heterogenous list using type families alone? I can do it using multiparameter type classes: class Del a list result instance Del a (a,list) list instance Del a list list' => Del a (a',list) list' instance Del a () () I tried to express the same using type families: type family Del a list type instance Del a () = () type instance Del a (a,list) = list type instance Del a (a',list) = (a',Del a list) to no avail. I got "conflicting family instance declarations" error. I tried to express that with associated type synonyms that contains both multiparameter type classes and type families: class HDel a list where type Del a list instance HDel a () where type Del a () = () instance HDel a (a,list) where type Del a (a,list) = list instance HDel a list => HDel a (a',list) where type Del a (a',list) = (a',Del a list) And I once again got "conflicting family instance declaration". It looks like right now there is no way to express type equality or inequality with type families, even when they are combined with multiparameter type classes. What is the right way to express something like that? Only MPTC? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Template Haskell sees into abstract data types
2010/7/28 Simon Peyton-Jones : > I assume you've seen http://hackage.haskell.org/trac/ghc/ticket/4222 > There are non-obvious design choices here Yes, I've seen that. Right now I just cannot grok it fully. I feel like I should share my current understanding with cafe, so I wrote them in my answer to Jonas. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Template Haskell sees into abstract data types
2010/7/28 Jonas Almström Duregård : > Hi, > >> I cannot write classes that see into internal structure. For example, >> I cannot write my own (de)serialization without using from/toAscList. > > Actually I don't believe you can do this with TH either. TH splices > code into the module where you use it. The generated code is then type > checked in this module. If constructors that are not exported are used > in the generated code, I believe you will get an error. > > This could still be an issue because your TH code won't know if the > constructors are exported or not, but i doubt you can actually do > things with TH that you can't do with plain H. I doubt that doubt first. ;) >> At least, it looks like I can, I didn't tried, actually. > Neither have I. So I did. And succeed: TH sees into data types. (ghc 6.12.1) Module A.hs, contains definition of abstract data type A, class Class and some primitive instance generator for that Class. Instance generator takes a data declaration name, takes first constructor (which should be argumentless) and makes it a value for definition of "c" function. -- {-# LANGUAGE TemplateHaskell #-} module A(A,Class(..),mkSimpleClass) where import Language.Haskell.TH data A = A1 | A2 deriving Show class Class a where c :: a mkSimpleClass :: Name -> Q [Dec] mkSimpleClass name = do TyConI (DataD [] dname [] cs _) <- reify name ((NormalC conname []):_) <- return cs ClassI (ClassD [] cname [_] [] [SigD mname _]) <- reify ''Class return [InstanceD [] (AppT (ConT cname) (ConT dname)) [FunD mname [Clause [] (NormalB (ConE conname)) [ -- Module B.hs, imports A.hs, uses mkSimpleClass on A.A name: -- {-# LANGUAGE TemplateHaskell #-} module B where import A $(mkSimpleClass ''A) -- I successfully loaded B.hs into ghci, Expression "c :: A" successfully evaluates to A1. My view on that problem is that we can add TyConIAbs for incompletely exported and abstract data types. When someone get TyConIAbs after reification, he will know that he doesn't know everything about that type. So, empty data declaration like "data Z" will return TyConI with empty list of constructors, TyConIAbs will have empty list of constructors for abstract data type. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Lists and monads
2010/7/26 Kevin Jardine : > I suspect that things are not quite as difficult as they appear, > however, but cannot find any tutorials on monadic list manipulation. I'd suggest that you get as many pure values as possible from impure world, apply to them easy to use pure functions (list processing, etc) to get the desired result and, only then, put result back into impure world. It is even more exciting because you can create and combine impure actions as pure values. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Design for 2010.2.x series Haskell Platform site
2010/7/17 Don Stewart : > > Here's a first cut in the repo with the new design converted to CSS > > http://code.haskell.org/haskell-platform/download-website/ > > If anyone would like to clean it up further, please send me patches to > the style.css file or index.html. I have big fonts (magnifyed by 3 or so in firefox) and it happens that text with "Robust" etc gets displayed over download icons. Other that that, it looks nice. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] trees and pointers
2010/7/15 Sergey Mironov : > 2010/7/15 Serguey Zefirov : >> 2010/7/14 Sergey Mironov : >>> Hi cafe! I have a question of C-to-Haskell type:) >>> >>> Imagine web application wich allows users to browse some shared >>> filesystem located at the server. >>> Application stores every users's position within that filesystem >>> (current directory or file). >>> >>> In C this can be implemented with the help of following data types: >>> >>> Any ideas? >> >> Use IORef. ;) >> >> PS >> MVar is better, actually. > Somehow I forgot about them:) Code will turn into something like > > It really should work! (we don't take multithreading issues into > account for now) > Slightly annoying thing is that 1-to-1 mapping from C to Haskell also > forces programmer to perform C-like low-level pointer linking. This is just straightforward solution and it contains some number of traps. What if someone disconnected a part of "file system" while some user browses it? That user will be trapped inside that island (or get a core dump), How do users get notifications about changes in their parts of structures? You can do better but, of course, it will be harder. The browsing itself is a simple variant of collaborative editing: http://en.wikipedia.org/wiki/Collaborative_editing Your variant is simpler that editing because only one member produce changes in structure. So you could send tree diffs in Zipper format to all your users or accumulate diffs and give them to users when they ask for it. Adding tree diff over user position described as Zipper won't put user into an isolated island. And if you later decide that there are two parties who can change the world, you are almost fully prepared for it. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] trees and pointers
2010/7/14 Sergey Mironov : > Hi cafe! I have a question of C-to-Haskell type:) > > Imagine web application wich allows users to browse some shared > filesystem located at the server. > Application stores every users's position within that filesystem > (current directory or file). > > In C this can be implemented with the help of following data types: > > Any ideas? Use IORef. ;) PS MVar is better, actually. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Float instance of Data.Bits
2010/7/9 Sam Martin : >> Some operations wouldn't make much sense with Float, for instance the >> 'complement' function. What should it return? Also note that bit >> manipulation functions could cover only a small window of the value >> range. So it could happen that x .|. y = x, even though y is nonzero. >> Also rotation would be a destructive operation. > > Perhaps I can illustrate this with an example. It's very common with SSE > code to interpret a float as both a mask and a number. You can exchange > the two freely. > > For instance, in c-like pseudo code, you can write: > float mask = myval == 0 ? 0x : 0x Notwithstanding mask is compatible with float sizeof-wize you should assign it a different type so you won't accidentally return a value of 0x. It is cumbersome in C, and much more easier in Haskell. Then you specify your operations over masks and floats, bind them to SSE2 primitives and use them as you wish. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Float instance of Data.Bits
2010/7/9 Ertugrul Soeylemez : > Sam Martin wrote: > Nobody would really need the operations (we have integer types and > UArray Int Bool for bit manipulation), and they would most likely be > very slow. They won't be slow using SSE2 or something. I can see where they could be beneficial. But I agree that those operations have semantics not compatible with Data.Bits operations. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] music-related problem
>> Actually, it would be wise to parametrize Item with computed >> attributes so that you can clearly distinguish between documents where >> soundedEnd is set from documents where it is not. > Ah, this sounds like something I am looking for... parameterizing Item with > the computed attributes. But I am not clear about what that would look > like. Would Item have kind * -> *? Like > data Item c = Item {pitch::Pitch, end::Loc, computed::c} > ? Yep. Item () means there soundEnd isn't set and Item Loc means we computed it. If you need more computed parameters, just tuple them. ;) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] music-related problem
> The thing that is hard for me to understand is how, in a functional > paradigm, to update the entire Doc by chasing down every tie and making > all necessary updates. This looks like one of graph algorithms. Notes are nodes, ties are arcs. Measures, etc are parts of node label. soundedEnd property can be computed over this. Actually, it would be wise to parametrize Item with computed attributes so that you can clearly distinguish between documents where soundedEnd is set from documents where it is not. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Template Haskell sees into abstract data types
>> I cannot directly create my own class instances for them because of >> that. But I found that I can write Template Haskell code that could do >> that - those data types could be reified just fine. > Huh? Sure you can write class instances for them. > , > | instance SizeOf (Map k v) where > | sizeOf = Map.size > ` Those are trivial. They are not interesting. I cannot write classes that see into internal structure. For example, I cannot write my own (de)serialization without using from/toAscList. >> This is somewhat strange situation. >> Was it a design decision? > The reason that they are exported abstractly is so that you don't see > the internals of the data structure, because 1) you don't need to, and > 2) to stop you from doing anything stupid with them. I was talking about successful reification of abstract data types. That way I can do anything stupid with them. At least, it looks like I can, I didn't tried, actually. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Template Haskell sees into abstract data types
Data.Map.Map and Data.Set.Set are exported abstractly, without exposing knowledge about their internal structure. I cannot directly create my own class instances for them because of that. But I found that I can write Template Haskell code that could do that - those data types could be reified just fine. This is somewhat strange situation. Was it a design decision? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How easy is it to hire Haskell programmers
> On Wed, Jun 30, 2010 at 4:34 PM, Paul Johnson wrote: >> I'm starting to see job adverts mentioning Haskell as a "nice to have", and >> even in some cases as a technology to work with. >> >> However right now I'm looking at it from the other side. Suppose someone >> wants to hire a Haskell developer or three. How easy is this? I'd >> appreciate replies from people who have actually done this. > > I guess it must be a lot easier to find applicants if you don't > require them to live in the same city/country as you. "Objection!" My experience (circa 2005) had shown that it is easy to hire Haskell programmers (in Moscow). We've got about ten resumes from single post in FIDO conference, most of them tried Haskell for small projects and were glad to use it for paying job. Only one or two of them had substantial previous Haskell experience but all resumes were from quite capable programmers. I think "Haskell is nice to have" is a convenient filter for good programmers. At least it was then. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How does one get off haskell?
2010/6/17 Günther Schmidt : > BTW this is not meant as a fun post, I'm actually quite serious, ie. I need > money, only way of getting it is doing Java, C# or PHP. > > So how does one get off haskell? Are there people in similar situations that > have managed? How did you do it? I should suggest code generation from Haskell to C#/Java and PHP. Like Barrelfish, Atom, HJScript and many others EDSLs out there. You will save yourself time, you will enjoy Haskell. Probably, you will have problems with management because your programs will appear there in their completeness very suddently. ;) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] TDD in Haskell
> I'm doing TDD in pretty much all of the languages that I know, and I want to > introduce it early in my Haskell learning process. I wonder though, if > there's some established process regarding TDD, not unit testing. TDD can be deciphered as Type Driven Design, and right now not so many languages would allow you to experience this. Take a look at this previous post here: http://www.haskell.org/pipermail/haskell-cafe/2010-May/077154.html ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] cabal-install
>>> I tried it and it didn't work. I don't know reason, though, maybe it >>> was because my current password not entirely alphanumeric. >> Shouldn't matter as long as you put it within quotes. > I imagine things will go wrong if it includes an @... urlencoding is > probably a smart idea. Thank you very much! I'll definitely try that. And, as I'm on it again, switch to just ignore proxy would be better. ;) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Bug with [Double]
2010/5/19 Erik de Castro Lopo : > Dmitry Olshansky wrote: > >> It seems that I saw something like this in Cafe recevtly. But I am not >> sure... >> In GHC 6.12.1 (Platform 2010 on Windows Vista) I have > > > > >> Any comments? > > The problem you point out is not a problem with Haskell, but a problem > with the whole concept of floating point arithmetic as implemented on > all modern CPUs. See: > > http://docs.sun.com/source/806-3568/ncg_goldberg.html > > You would have got similar problems with just about any language running > on the same hardware. This is what used for Double list generation (Haskell Platform 2010): -- numericEnumFromThenTo :: (Ord a, Fractional a) => a -> a -> a -> [a] numericEnumFromThenTo e1 e2 e3 = takeWhile predicate (numericEnumFromThen e1 e2) where mid = (e2 - e1) / 2 predicate | e2 >= e1 = (<= e3 + mid) | otherwise = (>= e3 + mid) -- So normal C loop like for {double i = 1; i <= 10; i += 1+2/3) { insert_list(i); } won't generate the same list, as Haskell does in [1,1+2/3..10]. PS Rationals: Prelude> [1,1+2/3..10] :: [Rational] [1 % 1,5 % 3,7 % 3,3 % 1,11 % 3,13 % 3,5 % 1,17 % 3,19 % 3,7 % 1,23 % 3,25 % 3,9 % 1,29 % 3,31 % 3] Same result. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] cabal-install
2010/5/19 Ivan Lazar Miljenovic : > Serguey Zefirov writes: >> Why there is no switch to turn off any use of proxy in cabal-install? >> Or to supply username/password pair in command line. >> I have a strange situation: wget works like charm ignoring proxy (I >> downloaded Cabal and cabal-install to investigate the problem using >> wget), Firefox works like charm igoring proxy, and only cabal cannot >> access anything, because it follows proper proxy protocol and our >> proxy requires username and password. > "Ignoring proxy"? Yes, they go right to internet. Firefox set to "No proxy" connection type. >> And I don't know of proper way to supply them through http_proxy >> environment variable. > export http_proxy="http://${username}:${passwo...@${proxy_url}"; I tried it and it didn't work. I don't know reason, though, maybe it was because my current password not entirely alphanumeric. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Performance Issue
2010/5/18 Richard Warburton : >> GHC performs almost no common subexpression elimination, the reasons being >> that it can introduce space leaks and undesired extra laziness. > Is there any way to encourage it to do so, for example compilation > flags? Or is it generally best to hand apply these kind of > optimisations. I think that handmade common expression elimination improves overall quality of code. ;) (as it amounts to refactoring it) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] cabal-install
Why there is no switch to turn off any use of proxy in cabal-install? Or to supply username/password pair in command line. I have a strange situation: wget works like charm ignoring proxy (I downloaded Cabal and cabal-install to investigate the problem using wget), Firefox works like charm igoring proxy, and only cabal cannot access anything, because it follows proper proxy protocol and our proxy requires username and password. And I don't know of proper way to supply them through http_proxy environment variable. The most annoying part is that it is too much work to download and build cabal using wget and scripts - I once tried it for some other utility and didn't succeed. PS And while I am on it, I'd like to suggest that cabal-install should read common options like credentials from environment or configuration file. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Hackage accounts and real names
2010/4/6 : > On Tue, 06 Apr 2010 20:06:27 +1000, Ivan Lazar Miljenovic > wrote: >>> I've been over this thread and couldn't see anywhere where you'd made >>> an attempt to refute these arguments, so I guess you take them as >>> solid. On the other hand, every argument put forward by the >>> pro-restriction group has been picked at and argued against by those >>> against the restriction. That is not a stalemate. >> >> A stalemate occurs when people disagree rather than one side having more >> compelling arguments. For example, I understand and respect your >> arguments; I just don't find them compelling enough (since I find it a >> pain trying to match up different nicks, etc.; though this is to do with >> the inconsistency you mention above). > So, what's next? Ban anyone hiding behind a nickname on the mailing list? > On IRC? On wiki? > This will bring you consistency. As a side effect, it will bring to the > Haskell > community the fame of being one of the most inadequate open source > communities. http://lambda-the-ultimate.org is one lovely community that has that restriction: http://lambda-the-ultimate.org/policies#Policies Actually, it's one of the best communities I know. I also think that many haskell-cafe readers agree on that. I also think that what is appropriate for mailing list is not appropriate for collective blog or site like hackage. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Apparently, Erlang does not have a static type system, since with hot code loading, this is intrinsically difficult.
2010/4/4 Casey Hawthorne : > Apparently, Erlang does not have a static type system, since with hot > code loading, this is intrinsically difficult. Apparently, this is doable with proper engineering even for such an unsafe language as C: http://www.cs.umd.edu/projects/PL/dsu/ > "Erlang Programming", Francesco Cesarini & Simon Thompson, June 2009, > O'Reilly, page 31. I think this is opinion from the time of Erlang design and initial prototypes which gets speaken repeatedly over and over again without (re)checking of facts. > If Haskell allows hot code loading, would this throw a wrench into the > static type system? The code that is loaded most often is the code of "state transformer" that operate on completely specified types of state and incoming messages. Behaviours (high level program composing "combinators" for Erlang) are pretty stable (and, as far as I can tell, are hard to reload - but I can be wrong). Again, one example of code reloading implemented for Bluetail Mail Robustifier actuall stops the system for complete code update and need special conversion code to update old state to new state invariants and back. I think that it is even easier in the presence of strong type system. And again: most of Erlang library code is annotated with type specifications for dialyzer. So I don't think that contemporary Erlang is dynamically typed. It's just static types does not used much. ;) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe