diff --git a/LICENSE b/LICENSE
new file mode 100644
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,27 @@
+Copyright (c) Henning Thielemann 2021
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+3. Neither the name of the author nor the names of his contributors
+   may be used to endorse or promote products derived from this software
+   without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
diff --git a/Makefile b/Makefile
new file mode 100644
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,4 @@
+run-test:
+	runhaskell Setup configure --user
+	runhaskell Setup build
+	runhaskell Setup haddock
diff --git a/Setup.lhs b/Setup.lhs
new file mode 100644
--- /dev/null
+++ b/Setup.lhs
@@ -0,0 +1,3 @@
+#! /usr/bin/env runhaskell
+> import Distribution.Simple
+> main = defaultMain
diff --git a/lapack-hmatrix.cabal b/lapack-hmatrix.cabal
new file mode 100644
--- /dev/null
+++ b/lapack-hmatrix.cabal
@@ -0,0 +1,44 @@
+Cabal-Version:    2.2
+Name:             lapack-hmatrix
+Version:          0.0
+License:          BSD-3-Clause
+License-File:     LICENSE
+Author:           Henning Thielemann <haskell@henning-thielemann.de>
+Maintainer:       Henning Thielemann <haskell@henning-thielemann.de>
+Homepage:         https://hub.darcs.net/thielema/lapack-hmatrix/
+Category:         Math
+Synopsis:         Conversion of objects between 'lapack' and 'hmatrix'
+Description:
+  Conversion of objects between 'lapack' and 'hmatrix'.
+Tested-With:      GHC==7.8.4
+Tested-With:      GHC==8.0.2, GHC==8.6.5, GHC==8.10.5
+Tested-With:      GHC==9.0.1
+Build-Type:       Simple
+Extra-Source-Files:
+  Makefile
+
+Source-Repository this
+  Tag:         0.0
+  Type:        darcs
+  Location:    https://hub.darcs.net/thielema/lapack-hmatrix/
+
+Source-Repository head
+  Type:        darcs
+  Location:    https://hub.darcs.net/thielema/lapack-hmatrix/
+
+Library
+  Build-Depends:
+    lapack >=0.4 && <0.5,
+    netlib-ffi >=0.1.1 && <0.2,
+    comfort-array >=0.4 && <0.6,
+    hmatrix >=0.17 && <0.21,
+    vector >=0.10 && <0.13,
+    transformers >=0.4 && <0.7,
+    utility-ht >=0.0.10 && <0.1,
+    base >=4.5 && <5
+
+  Default-Language: Haskell98
+  GHC-Options:      -Wall
+  Hs-Source-Dirs:   src
+  Exposed-Modules:
+    Numeric.LAPACK.HMatrix
diff --git a/src/Numeric/LAPACK/HMatrix.hs b/src/Numeric/LAPACK/HMatrix.hs
new file mode 100644
--- /dev/null
+++ b/src/Numeric/LAPACK/HMatrix.hs
@@ -0,0 +1,135 @@
+{-# LANGUAGE GADTs #-}
+module Numeric.LAPACK.HMatrix (
+   toVector,
+   fromVector,
+   toGeneral,
+   fromGeneral,
+   toHermitian,
+   fromHermitian,
+   fromOrder,
+   toOrder,
+   ) where
+
+import qualified Numeric.LAPACK.Matrix.Triangular as Triangular
+import qualified Numeric.LAPACK.Matrix.Hermitian as Hermitian
+import qualified Numeric.LAPACK.Matrix.Square as Square
+import qualified Numeric.LAPACK.Matrix.Layout as Layout
+import qualified Numeric.LAPACK.Matrix.Array as ArrMatrix
+import qualified Numeric.LAPACK.Matrix as Matrix
+import qualified Numeric.LAPACK.Scalar as Scalar
+import qualified Numeric.Netlib.Class as Class
+import Numeric.LAPACK.Matrix (ShapeInt)
+import Numeric.LAPACK.Vector (Vector)
+
+import qualified Numeric.LinearAlgebra.Devel as HMatrixDevel
+import qualified Numeric.LinearAlgebra.Data as HMatrixData
+import qualified Numeric.LinearAlgebra as HMatrix
+
+import qualified Data.Array.Comfort.Storable.Unchecked as Array
+import qualified Data.Array.Comfort.Shape as Shape
+import Data.Array.Comfort.Storable.Unchecked (Array(Array))
+
+import qualified Data.Vector.Storable as StVector
+
+import Data.Functor.Compose (Compose (Compose))
+import Data.Tuple.HT (mapPair)
+
+
+toVector ::
+   (StVector.Storable a) =>
+   StVector.Vector a -> Vector ShapeInt a
+toVector v =
+   let (fptr,n) = StVector.unsafeToForeignPtr0 v
+   in Array (Matrix.shapeInt n) fptr
+
+fromVector ::
+   (Shape.C shape, StVector.Storable a) =>
+   Vector shape a -> StVector.Vector a
+fromVector (Array shape fptr) =
+   StVector.unsafeFromForeignPtr0 fptr (Shape.size shape)
+
+
+toGeneral ::
+   (Class.Floating a) =>
+   HMatrix.Matrix a -> Matrix.General ShapeInt ShapeInt a
+toGeneral a =
+   case HMatrixDevel.orderOf a of
+      HMatrixDevel.RowMajor -> toRowMajor a
+      HMatrixDevel.ColumnMajor -> Matrix.transpose $ toRowMajor $ transpose a
+
+transpose :: (Class.Floating a) => HMatrix.Matrix a -> HMatrix.Matrix a
+transpose a =
+   case Scalar.complexSingletonOfFunctor a of
+      Scalar.Real ->
+         case Scalar.precisionOfFunctor a of
+            Scalar.Float -> HMatrix.tr' a
+            Scalar.Double -> HMatrix.tr' a
+      Scalar.Complex ->
+         case Scalar.precisionOfFunctor $ Compose a of
+            Scalar.Float -> HMatrix.tr' a
+            Scalar.Double -> HMatrix.tr' a
+
+toRowMajor ::
+   (Class.Floating a) =>
+   HMatrix.Matrix a -> Matrix.General ShapeInt ShapeInt a
+toRowMajor a =
+   let (dims, b) = flatten a
+   in Matrix.fromRowMajor $
+      Array.reshape (mapPair (Matrix.shapeInt, Matrix.shapeInt) dims) $
+      toVector b
+
+flatten ::
+   (Class.Floating a) => HMatrix.Matrix a -> ((Int,Int), StVector.Vector a)
+flatten a =
+   case Scalar.complexSingletonOfFunctor a of
+      Scalar.Real ->
+         case Scalar.precisionOfFunctor a of
+            Scalar.Float -> (HMatrixData.size a, HMatrix.flatten a)
+            Scalar.Double -> (HMatrixData.size a, HMatrix.flatten a)
+      Scalar.Complex ->
+         case Scalar.precisionOfFunctor $ Compose a of
+            Scalar.Float -> (HMatrixData.size a, HMatrix.flatten a)
+            Scalar.Double -> (HMatrixData.size a, HMatrix.flatten a)
+
+
+fromGeneral ::
+   (Shape.C height, Shape.C width, StVector.Storable a) =>
+   Matrix.General height width a -> HMatrix.Matrix a
+fromGeneral a =
+   HMatrixDevel.matrixFromVector
+      (fromOrder $ ArrMatrix.order a)
+      (Shape.size $ Matrix.height a)
+      (Shape.size $ Matrix.width a)
+      (fromVector $ ArrMatrix.unwrap a)
+
+
+toHermitian ::
+   (Class.Floating a) =>
+   HMatrix.Herm a -> Matrix.Hermitian ShapeInt a
+toHermitian =
+   ArrMatrix.fromVector . hermitianFromUpper . ArrMatrix.toVector .
+   Triangular.takeUpper . Square.fromFull . toGeneral . HMatrix.unSym
+
+hermitianFromUpper ::
+   Array (Layout.UpperTriangular sh) a -> Array (Layout.Hermitian sh) a
+hermitianFromUpper =
+   Array.mapShape (\sh -> sh{Layout.mosaicMirror = Layout.ConjugateMirror})
+
+fromHermitian ::
+   (Shape.C sh, Class.Floating a) =>
+   Matrix.Hermitian sh a -> HMatrix.Herm a
+fromHermitian =
+   HMatrix.trustSym . fromGeneral . Square.toFull . Hermitian.toSquare
+
+
+fromOrder :: Layout.Order -> HMatrixDevel.MatrixOrder
+fromOrder order =
+   case order of
+      Layout.RowMajor -> HMatrixDevel.RowMajor
+      Layout.ColumnMajor -> HMatrixDevel.ColumnMajor
+
+toOrder :: HMatrixDevel.MatrixOrder -> Layout.Order
+toOrder order =
+   case order of
+      HMatrixDevel.RowMajor -> Layout.RowMajor
+      HMatrixDevel.ColumnMajor -> Layout.ColumnMajor
