atzeus / hmap Goto Github PK
View Code? Open in Web Editor NEWFast heterogeneous maps in Haskell
License: Other
Fast heterogeneous maps in Haskell
License: Other
Related to #12
The same wrapping trick can get us an unsound type.
In the following we show that Char 'a' can be unsafely cast to Int 97.
Changing Int to (Int,Int) causes a seg fault.
Nick
{-#LANGUAGE ExistentialQuantification, RankNTypes #-}
module Main(main) where
import Data.HMap(HKey,HMap)
import qualified Data.HMap as HMap
data Wrapped a = forall x. Wrap (HKey x a)
w :: Wrapped a
w = HMap.withKey Wrap
hmap :: HMap
hmap = case w of Wrap k -> HMap.insert k 'a' HMap.empty
res :: Maybe Int -- replace Int with (Int,Int) for seg fault!
res = case w of Wrap k -> HMap.lookup k hmap
main :: IO ()
main = do
print res
{- Prints...
Just 97
-}
Hi!
Why is this library using weak pointers, from key to value?
When we add values to a map, there is no option to remove them from memory and they are stuck there until the key is deleted too. There are many use cases that you cannot remove the key (e.g updating value in a map) and need your app not too eat all the RAM.
Hi! It looks like master version have some compile issues
Resolving dependencies...
Notice: installing into a sandbox located at
/home/pmlodawski/dev/projects/HMap/.cabal-sandbox
Configuring text-1.2.1.1...
Configuring transformers-0.4.3.0...
Building text-1.2.1.1...
Building transformers-0.4.3.0...
Installed transformers-0.4.3.0
Configuring mtl-2.2.1...
Building mtl-2.2.1...
Installed mtl-2.2.1
Installed text-1.2.1.1
Configuring hashable-1.2.3.2...
Building hashable-1.2.3.2...
Installed hashable-1.2.3.2
Configuring unordered-containers-0.2.5.1...
Building unordered-containers-0.2.5.1...
Installed unordered-containers-0.2.5.1
Configuring HMap-1.2.3...
Building HMap-1.2.3...
Failed to install HMap-1.2.3
Build log ( /home/pmlodawski/dev/projects/HMap/.cabal-sandbox/logs/HMap-1.2.3.log ):
Configuring HMap-1.2.3...
Building HMap-1.2.3...
Preprocessing library HMap-1.2.3...
[1 of 6] Compiling Data.HideType ( Data/HideType.hs, dist/dist-sandbox-47edc933/build/Data/HideType.o )
[2 of 6] Compiling Data.HKeyPrivate ( Data/HKeyPrivate.hs, dist/dist-sandbox-47edc933/build/Data/HKeyPrivate.o )
[3 of 6] Compiling Data.Untypeable ( Data/Untypeable.hs, dist/dist-sandbox-47edc933/build/Data/Untypeable.o )
[4 of 6] Compiling Data.HKey ( Data/HKey.hs, dist/dist-sandbox-47edc933/build/Data/HKey.o )
[5 of 6] Compiling Data.HMap ( Data/HMap.hs, dist/dist-sandbox-47edc933/build/Data/HMap.o )
[6 of 6] Compiling Data.HKeySet ( Data/HKeySet.hs, dist/dist-sandbox-47edc933/build/Data/HKeySet.o )
Data/HKeySet.hs:75:11:
Not in scope: type constructor or class ‘Foldable’
cabal: Error: some packages failed to install:
HMap-1.2.3 failed during the building phase. The exception was:
ExitFailure 1
The doc for HKey.withKey states:
"The implementation actually creates a key, but because the key cannot escape the given function f, there is no way to observe that if we run withKey f twice, that it will get a different key the second time."
But in the following we see it is possible.
Nick
{-#LANGUAGE ExistentialQuantification, RankNTypes #-}
module Main(main) where
import Data.HMap as HMap
data Wrapped = forall x. Wrapped (HKey x ())
create :: () -> Wrapped
create () = HMap.withKey Wrapped
x,y,z :: Wrapped
x = create ()
y = create ()
z = y
comp :: Wrapped -> Wrapped -> Bool
comp (Wrapped key1) (Wrapped key2) = HMap.unique key1 == HMap.unique key2
main :: IO ()
main = do
print ("x~y",comp x y)
print ("x~z",comp x z)
print ("y~z",comp y z)
{- Prints...
("x~y",False)
("x~z",False)
("y~z",True)
-}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.