Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thautwarm/idris-python
Successor project: https://github.com/thautwarm/Quick-Backend
https://github.com/thautwarm/idris-python
idris idris-ecosystem python python3
Last synced: about 1 month ago
JSON representation
Successor project: https://github.com/thautwarm/Quick-Backend
- Host: GitHub
- URL: https://github.com/thautwarm/idris-python
- Owner: thautwarm
- License: bsd-3-clause
- Created: 2019-04-24T15:11:12.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-04-26T06:11:33.000Z (over 5 years ago)
- Last Synced: 2024-11-13T02:20:11.838Z (about 2 months ago)
- Topics: idris, idris-ecosystem, python, python3
- Language: Python
- Homepage:
- Size: 184 KB
- Stars: 24
- Watchers: 5
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
.. image:: https://img.shields.io/pypi/v/idris-python.svg
:target: https://pypi.python.org/pypi/idris-pythonidris-Python
==============Finally, we reached dependent types in Python side.
Requirements
===============* `The Haskell Tool Stack `_
* Python 3.7+
P.S: For users of Python3.7-, you can make a PR to remove the usages of
``dataclass`` and ``from __future__ import annotations`` to support
almost all Python versions, which I don't have time and motivations to deal
with.Install
================Firstly you should clone `Idris-Cam `_ and install
it:.. code ::
git clone https://github.com/thautwarm/idris-cam/
cd idris-cam
stack build
stack install # install idris-codegen-cam
stack install idris # install idris
cd libs
idris --install cam.ipkg # install cam modules for idrisThen install ``idris-python``,
.. code ::
pip install idris-python
Usage
====================- Command: Idris-Python
.. image:: https://raw.githubusercontent.com/thautwarm/idris-python/master/cmd-idris-python.png
:width: 90%
:align: center- Command: Run-Cam
.. image:: https://raw.githubusercontent.com/thautwarm/idris-python/master/cmd-run-cam.png
:width: 90%
:align: centerExample
===========================Quite verbose for the lack of encapsulations, not a good example but I'm too busy to work for this.
Following example just revealed that I've alredy implmented such a big task.
.. code-block :: idris
module Main
import Cam.FFI
import Cam.IO
import Cam.Data.Collections
import Cam.Data.FCollections
import Cam.Data.Compat
import Data.Vect
import Data.HVect%access export
main : IO ()
main = do
putStrLn $ show vect
sklearn <- camImport $ TheModule "sklearn.datasets"
load_iris <- camImportFrom sklearn "load_iris"
iris <- unsafeCall load_iris $ zero_ary
data' <- getattr iris "data"
tag <- getattr iris "target"
rfc <- let ensemble = camImport $ TheModule "sklearn.ensemble" in
camImportFrom !ensemble "RandomForestClassifier"
clf <- unsafeCall rfc zero_ary
fit <- getattr clf "fit"
unsafeCall fit . unsafe $ the (FList _) [data', tag]
score <- getattr clf "score"
value <- unsafeCall score . unsafe $ the (FList _) [data', tag] -- overfit
println value
where
vect : HVect [Int]
vect = the (HVect _) [1]zero_ary : Unsafe
zero_ary = unsafe $ the (FList Unsafe) $ []getattr' : IO Unsafe
getattr' = do
b <- camImport $ TheModule "builtins"
camImportFrom b "getattr"getattr : Unsafe -> String -> IO Unsafe
getattr obj s =
let s = unsafe . the (Boxed String) $ s in
let args = unsafe . the (FHVect [_, _]) $ [obj, toText s] in
unsafeCall !getattr' argsYou might got
.. code ::
[1]
0.99If you run it as a file with command ``idris-python``.